enumerate用法

  

Return an enumerate object. sequence must be a sequence, an iterator, or some other object which sup-
ports iteration. The next() method of the iterator returned by enumerate() returns a tuple containing
a count (from start which defaults to 0) and the corresponding value obtained from iterating over iter-
able. enumerate() is useful for obtaining an indexed series: (0, seq[0]), (1, seq[1]), (2,
seq[2]), .... 
 
For example:
>>> for i, season in enumerate([’Spring’, ’Summer’, ’Fall’, ’Winter’]):
...
 print i, season
0 Spring
1 Summer
2 Fall
3 Winter
原文地址:https://www.cnblogs.com/yum777/p/6108021.html