10 enumerate()在字典,列表中的用法详解

1.字典

li = {"alex"," aric","Alex","Tony","rain"}
for i,j in enumerate(li,1):
    new_j = j.strip()
    print(i,new_j)

 RESTART: C:/Users/wssar/AppData/Local/Programs/Python/Python37-32/1002q3.py
1 alex
2 Tony
3 Alex
4 aric
5 rain
>>>


2.列表
f = ["alex","tony","aleX","aric","rain"]
for i,j in enumerate(f):
print(i,j)

0 alex
1 tony
2 aleX
3 aric
4 rain
posted @ 2018-10-27 18:36  自由自在多快乐  阅读(897)  评论(0编辑  收藏  举报