How to add an index to each item in a list with Python

1 Answer

0 votes
lst = ['python', 'c', 'c++', 'c#', 'java']

list_of_tuples = list(enumerate(lst))

print(list_of_tuples)



     
     
'''
run:
     
[(0, 'python'), (1, 'c'), (2, 'c++'), (3, 'c#'), (4, 'java')]
  
'''

 



answered Apr 23, 2021 by avibootz
...