[Python] Memo dictionary

Python dictionary (dict) for loop processing (keys, values, items)

To loop the elements of the Python dictionary object dict with a for statement, use the methods keys (), values (), items () of the dictionary object dict.

test = {'key1': 1, 'key2': 2, 'key3': 3}

** keys (): for loop processing for each element key **

for A in test.keys():
    print(A)

# key1
# key2
# key3

** values (): for loop processing for each element value **

for B in test.values():
    print(B)

# 1
# 2
# 3

** items (): for loop processing for key and value of each element **

for C, D in test.items():
    print(C, D)

# key1 1
# key2 2
# key3 3

Recommended Posts

[Python] Memo dictionary
Python3 List / dictionary memo
Python memo
python memo
Python memo
python memo
Python memo
Python dictionary
[Python] dictionary
Python dictionary
Python memo
Python memo
python beginner memo (9.2-10)
python beginner memo (9.1)
[Python] Dictionary (hash)
Python basics: dictionary
★ Memo ★ Python Iroha
[Python] EDA memo
Python 3 operator memo
[My memo] python
Python3 metaclass memo
[Python] Basemap memo
Python beginner memo (2)
[Python] Numpy memo
Python class (Python learning memo ⑦)
My python environment memo
Python Basic Course (7 Dictionary)
python openCV installation (memo)
Python module (Python learning memo ④)
Visualization memo by Python
Python test package memo
[Python] Memo about functions
python regular expression memo
Binary search (python2.7) memo
[My memo] python -v / python -V
[Memo] Python3 list sort
Python Tips (my memo)
[Python] Memo about errors
DynamoDB Script Memo (Python)
Python Dictionary Beginner's Guide
Python basic memo --Part 2
python recipe book Memo
Basic Python command memo
Python OpenCV tutorial memo
Python basic grammar memo
TensorFlow API memo (Python)
python useful memo links
Python decorator operation memo
Python basic memo --Part 1
Effective Python Memo Item 3
Divisor enumeration Python memo
Python memo (for myself): Array
Python exception handling (Python learning memo ⑥)
Python list, for statement, dictionary
Python execution time measurement memo
Create a dictionary in Python
Python
Twitter graphing memo with Python
[Line / Python] Beacon implementation memo
Python and ruby slice memo
Python Basic Grammar Memo (Part 1)