Enumerate, enumeration functions
Return an enumerate object,enumerate was useful for obtaining an index list
Example 1: Generate a list and display its index
Import strings = List (string.uppercase) s = s[0:5]for i in range (len (s)): print I,s[i]
Example 2: generate a list and display its index
Import strings = List (string.uppercase) s = s[0:8]for index,i in enumerate (s): Print Index,i
Example 3: Define function Enumerate, pass in a sequence, generate a iterable
Import stringdef Enumerate (sequence, start=0): For i in Sequence:yield start,i start + = 1 List1 = String.uppercasedict1 = {"1": "A", "2": "B", "3": "C",}iterable_1 = Enumerate (list1) iterable_2 = Enumerate (DICT1) p Rint iterable_1.next () print iterable_1.next () print iterable_1.next () print iterable_2.next () print iterable_2.next () Print Iterable_2.next ()
This article from "Tornado" blog, declined reprint!
Python progresses a little bit every day---> enumerate