enumerate python
for index,char in enumerate("abcdef"):
print("{}-->{}".format(index,char))
0-->a
1-->b
2-->c
3-->d
4-->e
5-->f
enumerate python
for index,char in enumerate("abcdef"):
print("{}-->{}".format(index,char))
0-->a
1-->b
2-->c
3-->d
4-->e
5-->f
enumerate python
#Enumerate in python
l1 = ['alu','noodles','vada-pav','bhindi']
for index, item in enumerate(l1):
if index %2 == 0:
print(f'jarvin get {item}')
for enumerate 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
"""
enumerate python
animals = ["cat", "bird", "dog"]
#enumerate (For Index, Element)
for i, element in enumerate(animals,0):
print(i, element)
for x in enumerate(animals):
print(x, "UNPACKED =", x[0], x[1])
'''
0 cat
1 bird
2 dog
(0, 'cat') UNPACKED = 0 cat
(1, 'bird') UNPACKED = 1 bird
(2, 'dog') UNPACKED = 2 dog
'''
enumerate in Python
>>> def my_enumerate(sequence, start=0):
... n = start
... for elem in sequence:
... yield n, elem
... n += 1
...
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)
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