やりたいこと
python3.5
1sample_a = ([1,2,3],[2,3,4],[5,6,7,8]) 2list_product = list(itertools.product(sample_a[0], sample_a[1], sample_a[2]))
このコードにおいて、sample_aの配列数が可変(sample_a = ([1,2],[3,4])など)
であるので、
sample_a[0], sample_a[1], sample_a[2]とは記載せずに実現したい
失敗コード例
python3.5
1num = 3 2sample_a = ([1,2,3],[2,3,4],[5,6,7,8]) 3 4list_product = list(itertools.product(sample_a)) 5list_product = list(itertools.product(sample_a[i] for i in range(num)) 6
リスト内包表記と配列に対するそもそもの知識が足りていないのが原因だと思いますが、ご教授のほどお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/15 08:43