Looping Techniques

Looping Techniques

1、When looping through dictionaries, the key and corresponding value can be retrieved at the same time using the items() method.

  

2、enumerate(iterable, start=0)

  Return an enumerate object. iterable must be a sequence, an iterator, or some other object which supports iteration. The __next__() method of the iterator returned by enumerate() returns a tuple containing a count (from start which defaults to 0) and the values obtained from iterating over iterable.

  

  Equivalent to:

  

3、zip

  

4、sorted

  

5、reversed

  

  

原文地址:https://www.cnblogs.com/tekkaman/p/5800460.html