Pour énumérer Python
for key, value in enumerate(["p", "y", "t", "h", "o", "n"]):
print key, value
"""
0 p
1 y
2 t
3 h
4 o
5 n
"""
Weary Wombat
for key, value in enumerate(["p", "y", "t", "h", "o", "n"]):
print key, value
"""
0 p
1 y
2 t
3 h
4 o
5 n
"""
presidents = ["Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson"]
for num, name in enumerate(presidents, start=1):
print("President {}: {}".format(num, name))
array = ["one","two","three","four"]
arrayOfNumbers = []
mainArray = []
for i, x in enumerate(array):
arrayOfNumbers.append(i)
mainArray.append(x)
'''
>>print(arrayOfNumbers)
>>[0, 1, 2, 3]
>>print(mainArray)
>>["one","two","three","four"]
'''
# enumerate
for index, item in enumerate(['sanjose', 'cupertino', 'sunnyvale', 'fremont']):
print(index, ':', item)
# 0 : sanjose
# 1 : cupertino
# 2 : sunnyvale
# 3 : fremont