- Functional Python Programming
- Steven F. Lott
- 263字
- 2021-08-27 19:20:26
Working with Collections
Python offers a number of functions that process whole collections. They can be applied to sequences (lists or tuples), sets, mappings, and iterable results of generator expressions. We'll look at Python's collection-processing features from a functional programming viewpoint.
We'll start out by looking at iterables and some simple functions that work with iterables. We'll look at some design patterns to handle iterables and sequences with recursive functions as well as explicit for loops. We'll look at how we can apply a scalar function to a collection of data with a generator expression.
In this chapter, we'll show you examples of how to use the following functions with collections:
- any() and all()
- len(), sum(), and some higher-order statistical processing related to these functions
- zip() and some related techniques to structure and flatten lists of data
- reversed()
- enumerate()
The first four functions can be called reductions: they reduce a collection to a single value. The other three functions, zip(), reversed(), and enumerate(), are mappings; they produce a new collection from an existing collection(s). In the next chapter, we'll look at some more mapping and reduction functions that use an additional function as an argument to customize their processing.
In this chapter, we'll start out by looking at ways to process data, using generator expressions. Then, we'll apply different kinds of collection-level functions to show how they can simplify the syntax of iterative processing. We'll also look at some different ways of restructuring data.
In the next chapter, we'll focus on using higher-order collection functions to do similar kinds of processing.
- Oracle WebLogic Server 12c:First Look
- Apache ZooKeeper Essentials
- Learning ArcGIS Pro 2
- 程序員面試筆試寶典
- Android 7編程入門經(jīng)典:使用Android Studio 2(第4版)
- 程序員考試案例梳理、真題透解與強(qiáng)化訓(xùn)練
- C語(yǔ)言程序設(shè)計(jì)
- Java Web開(kāi)發(fā)技術(shù)教程
- Python數(shù)據(jù)結(jié)構(gòu)與算法(視頻教學(xué)版)
- 編程菜鳥(niǎo)學(xué)Python數(shù)據(jù)分析
- MySQL從入門到精通(軟件開(kāi)發(fā)視頻大講堂)
- Getting Started with React Native
- INSTANT Yii 1.1 Application Development Starter
- Spring技術(shù)內(nèi)幕:深入解析Spring架構(gòu)與設(shè)計(jì)原理(第2版)
- 你真的會(huì)寫代碼嗎