a=[[2,3],[3,4]]
b=[[5,6],[7,8],[9,10]]
c=[[11,12],[13,14],[15,16],[17,18]]
c1=[[11,12],[13,14],[15,16],[17,18]]
listr=[]
for number in range(96):
listr.append(number)
list = [[]]*96
for e in a:
for f in b:
for g in c:
for h in d:
for i in listr:
list[i].append(e)
list[i].append(f)
list[i].append(g)
print list
이 간단한 문제는 정말 어려움이 있습니다. 위 목록에서 가능한 모든 조합의 목록을 작성하고 싶습니다. [[2,3], [5,6], [11,12], [11,12]]와 같이 목록이 반복되면 첫 번째 조합은 [[2,3], [ 5,6], [11,12], [13,14]]. 이것은 좋은 시작은 아니지만, 어렵지는 않지만 프로그래밍 기술이 강하지 않다는 것을 안다. 나는 또한 각각의 목록에있는 각 목록의 첫 번째 번호를 추가하고 그들을 함께 추가하고 싶습니다 목록 및 목록 추가 목록 만들기
[[[2,3],[5,6],[11,12],[13,14]],[[2,3],[5,6],[11,12],[15,16]],[[2,3],[5,6],[11,12],[17,18]],...,[[3,4],[9,10],[15,16],[17,18]]]
처럼
최종 목록이 보일 것이다. [[31], [33], [35], ..., [44]
[순열] (https://docs.python.org/2/library/itertools.html#itertools.permutations), [조합] (https://docs.python.org/ 2/library/itertools.html # itertools.combinations), 'itertools'모듈의 [combinations_with_replacement] (https://docs.python.org/2/library/itertools.html#itertools.combinations_with_replacement) – proxy
c1이 사용되지 않습니다. d는 언급되지 않았다. 쓸모없는 d. 왜냐하면 ... for for는 너무 길다. 이러한 프로그래밍 스타일은 프로그래밍 시작 초기에 피하십시오. – chfw
@chfw : 저는 c1이 실제로 d라고 생각합니다. 그는 오타가 있습니다. d = [13,14], [15,16], [17,18], [19,20]] – Joe