Python: Loop Thru Dictionary

By Xah Lee. Date: . Last updated: .

Loop thru a dictionary's keys.

dd = {'john':3, 'mary':4, 'joe':5, 'vicky':7}

for kk in dd:
    print(kk)

# john
# mary
# joe
# vicky

Loop thru a dictionary, get both key and value.

# Loop thru a dictionary, get both key and value.

dd = {'john':3, 'mary':4, 'joe':5, 'vicky':7}

for kk, vv in dd.items():
    print(kk, ' is ', vv)

# john  is  3
# mary  is  4
# joe  is  5
# vicky  is  7

Python Data Structure

Python

Overview

Help

String

Arithmetic

Boolean

Conditional

Loop, Iteration

Data Structure

Function and Class

Module

Misc

Regex

Text Processing

Web

Misc