python's built-in function enumerate

enumerate is one of python's built-in functions, which is mainly used to obtain the index and element of an iterable object.

例子1:for i, n in enumerate(list):

                 print(i,n)

Can also be used to read the line count of a file:

Example 2: count = 0 

           for i, n in enumerate(open(file,'r')):

                     count += 1

           print(count)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324958982&siteId=291194637