確率や統計だったり、全パターン列挙などをする場合に便利な関数群を一部紹介。 これらの関数を使うことで複数のネストしたループを作らなくてすんで大変便利です。 組み合わせ combinations 例:5枚の数字カード[0..4]から3枚引いた時の取れるカードの組み合わせ。順番は関係なし >>> import itertools >>> list(itertools.combinations(range(5), 3)) [(0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 2, 3), (0, 2, 4), (0, 3, 4), (1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)] 順列 permutations 例:4枚の数字カード[0..3]の並び順のパターン。 >>> import itertools >>> list(iterto