Python: Enumerate List

By Xah Lee. Date: . Last updated: .
aa = [1,2,3, "inf"]

for xx in aa:
    print(xx)

# 1
# 2
# 3
# inf

get both index and value.

bb = ['one', 'two', 'three', 'infinity']

for ii, vv in enumerate(bb):
    print(ii, vv)

# 0 one
# 1 two
# 2 three
# 3 infinity

Python Data Structure

Python

Overview

Help

String

Arithmetic

Boolean

Conditional

Loop, Iteration

Data Structure

Function and Class

Module

Misc

Regex

Text Processing

Web

Misc