1languages = ['Python', 'C', 'C++', 'C#', 'Java']
2
3#Bad way
4i = 0 #counter variable
5for language in languages:
6 print(i, language)
7 i+=1
8
9#Good Way
10for i, language in enumerate(languages):
11 print(i, language)
12
1for index,subj in enumerate(subjects):
2 print(index,subj) ## enumerate will fetch the index
3
40 Statistics
51 Artificial intelligence
62 Biology
73 Commerce
84 Science
95 Maths
1for index,char in enumerate("abcdef"):
2 print("{}-->{}".format(index,char))
3
40-->a
51-->b
62-->c
73-->d
84-->e
95-->f
1>>> frutas = ["manzanas", "peras", "naranjas"]
2>>> for i, fruta in enumerate(frutas):
3... print(i, fruta)
40 manzanas
51 peras
62 naranjas
1#Enumerate in python
2l1 = ['alu','noodles','vada-pav','bhindi']
3for index, item in enumerate(l1):
4 if index %2 == 0:
5 print(f'jarvin get {item}')
1The enumerate() function assigns an index to each item in an
2iterable object that can be used to reference the item later.
3What does enumerate do in Python? It makes it easier to keep
4track of the content of an iterable object.