같은 것을 반환 itertools
로 : 파이썬 < 2.6이있는 경우
>>> from collections import Counter
>>> from itertools import combinations
>>> l = [[10, 11, 15], [12], [12, 11], [10, 11]]
>>> c = Counter(x for sub in l for x in combinations(sub, 2))
>>> for k, v in c.iteritems():
... print k, v
...
(10, 15) 1
(11, 15) 1
(10, 11) 2
(12, 11) 1
, 당신은,821,853,917을 사용할 수 있습니다과 조합 된(확실한 전문가의 한 사람이 깨끗한 해결책을 제공 할 것입니다).
In [1]: from collections import defaultdict
In [2]: from itertools import combinations
In [3]: l = [[10, 11, 15], [12], [12, 11], [10, 11]]
In [4]: counts = defaultdict(int)
In [5]: for x in l:
...: for item in combinations(x, 2):
...: counts[item] += 1
...:
...:
In [6]: for k, v in counts.iteritems():
...: print k, v
...:
...:
(10, 15) 1
(11, 15) 1
(10, 11) 2
(12, 11) 1
'list'처럼 보이지 않는? –
숙제입니까? –
왜 두 언어 태그가 필요합니까? –