Python: Loop Thru List

By Xah Lee. Date: . Last updated: .

Loop Thru List

# -*- coding: utf-8 -*-
# python
# Loop thru a list.

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

for xx in aa:
    print xx

Loop thru a list, and get both index and value.

# -*- coding: utf-8 -*-
# python
# Loop thru a list, and 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