-2

For example:I Have following List.

list1=["a","b","c","d"]

How to get both iterator number(in below code that is iteration) and item of list in the same for loop.I can write with following two loop .

for iteration in len(list1):
    for each_item in list1:
        #logic related to each_item
Devenepali
  • 145
  • 2
  • 8

1 Answers1

1
for i,  item in enumerate(list1):
    print(i, item)
ComplicatedPhenomenon
  • 3,863
  • 2
  • 14
  • 39