今天看源码的时候看到这样一段:
for i, score in enumerate(top_scores):
不知道是什么意思就查了一下手册,手册是这么说的:
enumerate()函数可以同时取出列表(元组)中的成员的索引和内容
也就是说采用原始的办法,上面的代码应该这么的写:
for i in range(len(top_scores)):
index = i
item = top_scores[i]
这样看应该就一目了然enumerate()的用法了
今天看源码的时候看到这样一段:
for i, score in enumerate(top_scores):
enumerate()函数可以同时取出列表(元组)中的成员的索引和内容
也就是说采用原始的办法,上面的代码应该这么的写:
for i in range(len(top_scores)):
index = i
item = top_scores[i]
这样看应该就一目了然enumerate()的用法了