Answers for "python enumerate list"

82

enumerate in python

languages = ['Python', 'C', 'C++', 'C#', 'Java']

#Bad way
i = 0 #counter variable
for language in languages:
    print(i, language)
    i+=1

#Good Way
for i, language in enumerate(languages):
    print(i, language)
Posted by: Guest on May-02-2020
2

python enumerate list

>>> for count, value in enumerate(values):
...     print(count, value)
...
0 a
1 b
2 c
Posted by: Guest on April-21-2021
4

python for enumerate loop

>>> values = ["a","b","c"]
>>> for count, value in enumerate(values):
...     print(count, value)
...
0 a
1 b
2 c
Posted by: Guest on December-23-2020
4

how to use enumerate in python

rhymes=['check','make','rake']
for rhyme in enumerate(rhymes):
    print(rhyme)
#prints out :
(0, 'check')
(1, 'make')
(2, 'rake')
#basically just prints out list elements with their index
Posted by: Guest on June-26-2020
0

enumerate python

grocery = ['bread', 'milk', 'butter']

for item in enumerate(grocery):
  print(item)

print('\n')
for count, item in enumerate(grocery):
  print(count, item)

print('\n')
# changing default start value
for count, item in enumerate(grocery, 100):
  print(count, item)
  
OUTPUT: 
(0, 'bread')
(1, 'milk')
(2, 'butter')

0 bread
1 milk
2 butter

100 bread
101 milk
102 butter
Posted by: Guest on January-02-2021
0

for enumerate python

for key, value in enumerate(["p", "y", "t", "h", "o", "n"]):
    print key, value

"""
0 p
1 y
2 t
3 h
4 o
5 n
"""
Posted by: Guest on June-21-2020

Python Answers by Framework

Browse Popular Code Answers by Language