0

私はプロジェクト Euler の問題に取り組んでおり、リストに int 要素を追加するすべての組み合わせを取得する必要があります。

from itertools import combinations
evenAbs = [12, 18, 20, 24, 30,36]
evenCombs =  sorted(([i+j for i,j in combinations(evenAbs, 2)]))

私の問題は、12+12 18+18 などを含む組み合わせが必要だということです。どうすればこれを行うことができますか?

4

1 に答える 1

2

使用itertools.combinations_with_replacement:

>>> import itertools
>>> list(itertools.combinations_with_replacement([1,2,3], 2))
[(1, 1), (1, 2), (1, 3), (2, 2), (2, 3), (3, 3)]
于 2013-10-26T05:54:29.287 に答える