Python中enumerate的用法

2017-01-13 19:11:30来源:CSDN作者:Mrzhangjwei人点击

Python中enumerate的用法:

>>> seasons = ['Spring', 'Summer', 'Fall', 'Winter']>>> list(enumerate(seasons))[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]>>> list(enumerate(seasons, start=1))[(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]
def enumerate(sequence, start=0):    n = start    for elem in sequence:        yield n, elem        n += 1

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台