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
1>>> for count, value in enumerate(values):
2... print(count, value)
3...
40 a
51 b
62 c
7
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#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}')
1rhymes=['check','make','rake']
2for rhyme in enumerate(rhymes):
3 print(rhyme)
4#prints out :
5(0, 'check')
6(1, 'make')
7(2, 'rake')
8#basically just prints out list elements with their index