LoginSignup
21
18

More than 5 years have passed since last update.

複数の配列の値のあらゆる組み合わせを調べる

Last updated at Posted at 2014-03-03

itertools.productで簡単にできるようでした。プログラミング問題を解いたり、あらゆる値で問題が出ないか網羅的な検査をするテストを書く際には便利そうですね。

import itertools
numbers = (1, 2, 3)
people = ('Alice', 'Bob')
for person, number in itertools.product(people, numbers):
    print '%s => %d' % (person, number)

結果は次のようになります。

Alice => 1
Alice => 2
Alice => 3
Bob => 1
Bob => 2
Bob => 3
21
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
18