Answers for "enumerate in python 3"

24

enumerate python

for index,subj in enumerate(subjects):
    print(index,subj) ## enumerate will fetch the index
    
0 Statistics
1 Artificial intelligence
2 Biology
3 Commerce
4 Science
5 Maths
Posted by: Guest on April-25-2020
12

enumerate python

for index,char in enumerate("abcdef"):
  print("{}-->{}".format(index,char))
  
0-->a
1-->b
2-->c
3-->d
4-->e
5-->f
Posted by: Guest on May-21-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
1

enumerate in python

list1 = ['1', '2', '3', '4']

for index, listElement in enumerate(list1): 
    #What enumerate does is, it gives you the index as well as the element in an iterable
    print(f'{listElement} is at index {index}') # This print statement is just for example output

# This code will give output : 
"""
1 is at index 0
2 is at index 1
3 is at index 2
4 is at index 3
"""
Posted by: Guest on November-25-2020
0

enumerate in Python

>>> def my_enumerate(sequence, start=0):
...     n = start
...     for elem in sequence:
...         yield n, elem
...         n += 1
...
Posted by: Guest on April-19-2021

Python Answers by Framework

Browse Popular Code Answers by Language