Use items () to retrieve one by one in a for loop.
sample.py
dict = {
"A": 1,
"B": 2,
"C": 3
}
for dict_str, dict_num in dict.items():
print(dict_str,dict_num,sep="→")
#Output result
# A→1
# B→2
# C→3
Looking at the contents, there are tuples in the list.
sample.py
print(dict.items())
#Output result
# dict_items([('A', 1), ('B', 2), ('C', 3)])
These tuples are unpacked
A → dict_str 1 → dict_num
It can be read that it is in.
Recommended Posts