-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
  • 157
  • 3
  • 9

1 Answers1

1
for i,  item in enumerate(list1):
    print(i, item)
ComplicatedPhenomenon
  • 4,055
  • 2
  • 18
  • 45