官术网_书友最值得收藏!

Summary

In this chapter, we saw detailed ways to use a number of built-in reductions.

We've used any() and all() to do essential logic processing. These are tidy examples of reductions using a simple operator, such as or or and.

We've also looked at numeric reductions such as, len() and sum(). We've applied these functions to create some higher-order statistical processing. We'll return to these reductions in Chapter 6, Recursions and Reductions.

We've also looked at some of the built-in mappings.

The zip() function merges multiple sequences. This leads us to look at using this in the context of structuring and flattening more complex data structures. As we'll see in examples in later chapters, nested data is helpful in some situations and flat data is helpful in others.

The enumerate() function maps an iterable to a sequence of two-tuples. Each two-tuple has the sequence number at index [0] and the original value at index [1].

The reversed() function iterates over the items in a sequence object, with their original order reversed. Some algorithms are more efficient at producing results in one order, but we'd like to present these results in the opposite order.

In the next chapter, we'll look at the mapping and reduction functions that use an additional function as an argument to customize their processing. Functions that accept a function as an argument are our first examples of higher-order functions. We'll also touch on functions that return functions as a result.

主站蜘蛛池模板: 茂名市| 肇东市| 拉萨市| 黑龙江省| 昌邑市| 来宾市| 昭通市| 剑川县| 临汾市| 页游| 靖州| 宣威市| 鱼台县| 富阳市| 合作市| 芦山县| 柳河县| 邛崃市| 饶阳县| 雅江县| 乌拉特中旗| 武强县| 洪泽县| 汝城县| 同仁县| 泰和县| 威信县| 旬阳县| 巴林左旗| 楚雄市| 扶风县| 尚义县| 普兰店市| 桂阳县| 中江县| 仁化县| 花垣县| 沅江市| 东兰县| 明光市| 广安市|