Story when iterating python tuple

I learned that I can write like this. I used 2.7.11, but I wonder if 3 is the same.

items = [1, 2, 3, 4, 5]
pairs = [('aaa', 100), ('bbb', 200) ,('ccc', 300), ('ddd', 400), ('fff', 500)]

for key, value in pairs:
    print key, value
#>>>
#aaa 100
#bbb 200
#ccc 300
#ddd 400
#fff 500

for item, pair in zip(items, pairs):
    print item, pair[0], pair[1]    
#>>>
#1 aaa 100
#2 bbb 200
#3 ccc 300
#4 ddd 400
#5 fff 500

for item, (key, value) in zip(items, pairs):
    print item, key, value
#>>>
#1 aaa 100
#2 bbb 200
#3 ccc 300
#4 ddd 400
#5 fff 500

Recommended Posts

Story when iterating python tuple
Python> tuple> tuple unpacking
A story when a Python user passes a JSON file
python small story collection
Troublesome story when using Python3 with VScode on ubuntu
Stumble story with Python array
Specify options when running python
Attention when os.mkdir in Python
Error when playing with python
GAE + python + Django addictive story
python> tuple> data, address = s.recvfrom (10000)
[Python, Selenium, PhantomJS] A story when scraping a website with lazy load
[Python] Tuple version of prefecture pull-down
[python] Error when installing library ramkan
Python tuple comprehensions and generator expressions
The story of Python and the story of NaN
Precautions when using pit in Python
Check the behavior when assigning Python
Error when building mac python environment
Behavior when listing in Python heapq
Support when installing pillow on python3.9
[Small story] Get timestamp with Python
[Python] Be careful when using print
Precautions when creating a Python generator
Python --Symbols used when performing operations
Precautions when using phantomjs from python
When matplotlib doesn't work with python2.7
Use gcc-4.2 when compiling Python (MacOS)
Strange and horrifying Python error story
When using MeCab with virtualenv python
Python> tuple> Convert double tuple to single tuple
Precautions when using six with Python 2.5
[VS Code] ~ Tips when using python ~
Story of power approximation by Python
When using regular expressions in Python
When writing a program in Python
Eliminate WARNING when starting Python IDLE
[Python] Format when to_csv with pandas
A story I was addicted to when inserting from Python to a PostgreSQL table