Python Object-oriented Shortcuts(Chapter 7 of Python 3 Object Oriented Programmi
时间:2010-09-03 来源:Ray Z
Reversed
The reversed() function takes any sequence as input, and returns a copy of that sequence in reverse order.
Enumerate
Sometimes when we're looping over an iterable object in a for loop, we want access to the index (the current position in the list) of the current item being processed. The for loop doesn't provide us with indexes, but the enumerate function gives us something better: it creates a list of tuples, where the first object in each tuple is the index and the second is the original item.
Zip
The zip function is one of the least object-oriented functions in Python's collection. It takes two or more sequences and creates a new sequence of tuples. Each tuple contains one element from each list.
Three more functions that operate on sequences are min, max, and sum. These each take a sequence as input, and return the minimum or maximum value, or the sum of all values in the sequence.