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
posted @ 2016-11-28 00:15  whitesky-root  阅读(158)  评论(0编辑  收藏  举报