- 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.
- OpenStack Cloud Computing Cookbook(Third Edition)
- 自己動手實現Lua:虛擬機、編譯器和標準庫
- C#程序設計(慕課版)
- Mastering Scientific Computing with R
- SEO智慧
- Mastering Yii
- 你必須知道的204個Visual C++開發問題
- R的極客理想:工具篇
- Microsoft System Center Orchestrator 2012 R2 Essentials
- C#程序設計
- Python爬蟲、數據分析與可視化:工具詳解與案例實戰
- Visual Basic程序設計習題與上機實踐
- GameMaker Essentials
- JBoss:Developer's Guide
- Mastering HTML5 Forms