Skip to content

2023 07 12

【Python】itertools.product(*iterables, repeat=1)

https://docs.python.org/ja/3/library/itertools.html#itertools.product 入力されたイテラブルのデカルト積(直積)を返す。

itertools.product('ABC', 'xy') # --> Ax Ay Bx By Cx Cy
itertools.product(range(2), repeat=3) # --> 000 001 010 011 100 110 101 111
https://atcoder.jp/contests/typical90/tasks/typical90_b 上記問題ではitertoos.product("()", repeat=N)のようにして候補を全列挙できる。