Dictionary-type processing using items ()

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

Dictionary-type processing using items ()
Implement reversi reversi processing using BitBoard
Using Python mode in Processing
[Linux] Accelerate compression processing using pigz
100 language processing knock-76 (using scikit-learn): labeling
Environmentally friendly scraping using image processing
100 Language Processing Knock-31 (using pandas): Verb
Horizon processing using OpenCV morphology transformation
Japanese analysis processing using Janome part1
100 language processing knock-73 (using scikit-learn): learning
100 language processing knock-74 (using scikit-learn): Prediction
I tried asynchronous processing using asyncio
100 Language Processing Knock-38 (using pandas): Histogram
100 language processing knock-97 (using scikit-learn): k-means clustering
Periodic execution processing when using tkinter [Python3]
[Python] Speeding up processing using cache tools
100 Language Processing Knock-33 (using pandas): Sahen noun
[Python] Matrix multiplication processing time using NumPy
Asynchronous processing using Linebot in Job queue
Usual processing notes when using Google Colaboratory
100 Language Processing Knock-71 (using Stanford NLP): Stopword
WEB application development using Django [Request processing]
100 Language Processing Knock-35 (using pandas): Noun concatenation
[Python] Various data processing using Numpy arrays
Perform arbitrary processing during installation using setuptools
100 Language Processing Knock-39 (using pandas): Zipf's Law
Video processing using Python + OpenCV on Mac
100 Language Processing Knock-34 (using pandas): "A B"