Logo

Programming-Idioms

History of Idiom 7 > diff from v136 to v137

Edit summary for version 137 by rkrikbaev:
[Python] test

Version 136

2022-09-02, 22:27:21

Version 137

2022-10-05, 05:06:10

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Variables
i,x,items
Variables
i,x,items
Extra Keywords
indices traverse traversal
Extra Keywords
indices traverse traversal
Code
for i, x in enumerate(items):
    print i, x
Code
list = [x[1] for x in items]
Doc URL
https://docs.python.org/3/library/functions.html#enumerate
Doc URL
https://docs.python.org/3/library/functions.html#enumerate
Origin
https://stackoverflow.com/a/522578/871134
Origin
https://stackoverflow.com/a/522578/871134