Python> Comprehension> cells> I was taught how to use double comprehension / itertools

@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic (No. 2351 / 12833)

There is an example of making a table using comprehension notation.

http://ideone.com/QJqVpn

rows = range(1,4)
cols = range(1,3)
cells = [(row, col) for row in rows for col in cols]
for cell in cells:
	print(cell)

result


Success	time: 0 memory: 23968 signal:0
(1, 1)
(1, 2)
(2, 1)
(2, 2)
(3, 1)
(3, 2)

Matters taught

(Addition 2017/03/24)

@ shiracamus's Comment taught me how to use itertools.

Thank you for the information.

Recommended Posts

Python> Comprehension> cells> I was taught how to use double comprehension / itertools
python3: How to use bottle (2)
[Python] How to use list 1
How to use Python argparse
Python: How to use pydub
[Python] How to use checkio
I tried to summarize how to use pandas in python
[Python] How to use input ()
How to use Python lambda
[Python] How to use virtualenv
python3: How to use bottle (3)
python3: How to use bottle
How to use Python bytes
I didn't know how to use the [python] for statement
Python: How to use async with
[Python] How to use Pandas Series
How to use Requests (Python Library)
How to use SQLite in Python
[Python] How to use list 3 Added
How to use Mysql in python
How to use FTP with Python
Python: How to use pydub (playback)
How to use PubChem in Python
How to use python zip function
[Python] How to use Typetalk API
How to use Python Kivy (reference) -I translated Kivy Language of API reference-
[Python] Summary of how to use pandas
[Introduction to Python] How to use class in Python?
How to install and use pandas_datareader [Python]
I want to use jar from python
[Python] How to use import sys sys.argv
[Python] Organizing how to use for statements
Memorandum on how to use gremlin python
[Python2.7] Summary of how to use unittest
python: How to use locals () and globals ()
How to use __slots__ in Python class
How to use "deque" for Python data
How to use Python zip and enumerate
[Python] Understand how to use recursive functions
Summary of how to use Python list
How to use regular expressions in Python
[Python2.7] Summary of how to use subprocess
What I was addicted to Python autorun
How to use is and == in Python
[Blender x Python] How to use modifiers
[Question] How to use plot_surface of python
Use Python from Java with Jython. I was also addicted to it.
[Python] I was hooked for an hour trying to use list comprehensions
How to use the C library in Python
[Python] How to use two types of type ()
I want to use MATLAB feval with python
Study from Python Hour7: How to use classes
I was able to recurse in Python: lambda
How to use Raspberry Pi pie camera Python
How to use Python Kivy ④ ~ Execution on Android ~
Summary of how to use MNIST in Python
I want to use Temporary Directory with Python2
I want to use ceres solver from python
How to use tkinter with python in pyenv
[Python] How to use hash function and tuple.
How to use Ruby's PyCall to enable pyenv Python