[Python collection] enumerate () function, pythonenumerate
When processing various sequences in python, if we wantShow the elements of this sequence and Their subscriptYou can use the enumerate () function.
The enumerate () function is used to traverse elements in a sequence and Their subscript. The usage is as follows:
1. the parameter is a tuple:
For index, value in enumerate ('A', 'B', 'C'): '''subscript, element ''' print (index, value)
2. the parameter is a list:
For index, value in enumerate ([1, 2, 3]): ''' subscript, element ''' print (index, value)
3. the parameter is a string:
For index, value in enumerate ('abc'): ''' subscript, element ''' print (index, value)
4. the parameter is a dictionary dict:
For index, value in enumerate ({'A': 1, 'B': 2}): ''' subscript (Dictionary unordered), element (Key value) '''print (index, value)