Ray's playground

 

Python Object-oriented Shortcuts(Chapter 7 of Python 3 Object Oriented Programming)

  Len
  The simplest example is the len() function. This function counts the number of items in some kind of container object such as a dictionary or list.

  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. 

posted on 2010-09-03 20:44  Ray Z  阅读(292)  评论(0编辑  收藏  举报

导航