enumerate in Python
>>> for count, value in enumerate(values):
... print(count, value)
...
0 a
1 b
2 c
enumerate in Python
>>> for count, value in enumerate(values):
... print(count, value)
...
0 a
1 b
2 c
enumerate in Python
grocery = ['bread', 'milk', 'butter']
for item in enumerate(grocery):
print(item)
print('\n')
for count, item in enumerate(grocery):
print(count, item)
print('\n')
# changing default start value
for count, item in enumerate(grocery, 100):
print(count, item)
enumerate items python
mydict = {1: 'a', 2: 'b'}
for i, (k, v) in enumerate(mydict.items()):
print("index: {}, key: {}, value: {}".format(i, k, v))
# which will print:
# -----------------
# index: 0, key: 1, value: a
# index: 1, key: 2, value: b
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us