【Perl,PHP】LLバトルロワイヤル13【Ruby,Python】
■ このスレッドは過去ログ倉庫に格納されています
0790デフォルトの名無しさん
2010/11/14(日) 22:13:102.6からはあるよ。
itertools.product(*iterables[, repeat])
ttp://docs.python.org/library/itertools.html#itertools.product
コード例もそこに載ってて、
def product(*args, **kwds):
# product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
# product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
pools = map(tuple, args) * kwds.get('repeat', 1)
result = [[]]
for pool in pools:
result = [x+[y] for x in result for y in pool]
for prod in result:
yield tuple(prod)
product([1,2,3],"AB","xy")
が、>>783と全く同じ結果を返す。
■ このスレッドは過去ログ倉庫に格納されています