>>> A = [2,0,1,3,2,2,0,1,1,2,0]
>>> A = sorted(set(A)) # list(set(A)) is not usually in order
>>> from itertools import combinations
>>> list(combinations(A, 2))
[(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]
>>> map(list, combinations(A, 2))
[[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3]]
>>> help(combinations)
Help on class combinations in module itertools:
class combinations(__builtin__.object)
| combinations(iterable, r) --> combinations object
|
| Return successive r-length combinations of elements in the iterable.
|
| combinations(range(4), 3) --> (0,1,2), (0,1,3), (0,2,3), (1,2,3)
|
| Methods defined here:
|
| __getattribute__(...)
| x.__getattribute__('name') <==> x.name
|
| __iter__(...)
| x.__iter__() <==> iter(x)
|
| next(...)
| x.next() -> the next value, or raise StopIteration
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __new__ = <built-in method __new__ of type object>
| T.__new__(S, ...) -> a new object with type S, a subtype of T
덕분에 ... 난 그냥 조합이 실제로 제대로 작동 것을 noticted. 방금 조합 함수가 [2,0132201120]의 모든 조합을 만드는 원인이 된 A = list (Set (A))를 지정하는 것을 잊었습니다. – WGL
@WGL, 나는 방금 질문 제목에서 "정렬"을 발견했습니다. 'list (set (A))'대신'sorted (set (A))'를 사용해야합니다. –