2017-12-27 15 views
-2

매우 간단한 작업을 수행 할 때 CoCalc (Sage는 일부 추가 된 Python 2.7 임)에서 프로그래밍 중이며 문제가 있습니다. 나는 빈번한 프로그래머가 아니라는 것을 인정해야한다. 그래서 나는 분명히 분명해야 할 무언가를 놓치고있을 것이다.IndexError : 중첩 된 for 루프를 사용하여 범위를 벗어난 인덱스 색인

문맥 안에 질문을두기 위하여. max_faces_list는 세트 목록입니다. 목록에서 다른 요소의 하위 집합 인 요소를 제거하고 싶습니다.

코드는 :

for i in range(0,len(max_faces_list)-2): 
i 
for j in range(i+1,len(max_faces_list)): 
    j 
    if max_faces_list[i].issubset(max_faces_list[j]): 
     print('bu') 
     F.remove(F[i]) 
     break    

출력은 : 일부 코드를 (I, J 및 인쇄를 도입

max_faces_list=[set([(0, 2, 3)]), set([(0, 1, 2)]), set([(1, 2, 3)]), set([(0, 1, 3)]), set([(0, 2, 3), (0, 1, 2)]), set([(0, 2, 3), (1, 2, 3)]), set([(0, 2, 3), (0, 1, 3)]), set([(0, 1, 2), (1, 2, 3)]), set([(0, 1, 2), (0, 1, 3)]), set([(1, 2, 3), (0, 1, 3)]), set([(0, 2, 3), (0, 1, 2), (1, 2, 3)]), set([(0, 2, 3), (0, 1, 2), (0, 1, 3)]), set([(0, 2, 3), (1, 2, 3), (0, 1, 3)]), set([(0, 1, 2), (1, 2, 3), (0, 1, 3)])] 

F=[Simplicial complex with vertex set (0, 2, 3) and facets {(0, 2, 3)}, Simplicial complex with vertex set (0, 1, 2) and facets {(0, 1, 2)}, Simplicial complex with vertex set (1, 2, 3) and facets {(1, 2, 3)}, Simplicial complex with vertex set (0, 1, 3) and facets {(0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(1, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (1, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (1, 2, 3), (0, 1, 3)}] 

:

이 경우
0 
1 
2 
3 
4 
bu 
1 
2 
3 
4 
bu 
2 
3 
4 
5 
bu 
3 
4 
5 
6 
bu 
4 
5 
6 
7 
8 
9 
10 
bu 
5 
6 
7 
8 
9 
10 
bu 
6 
7 
8 
9 
10 
11 
bu 
7 
8 
9 
10 
bu 
Error in lines 1-8 
Traceback (most recent call last): 
    File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1013, in execute 
    exec compile(block+'\n', '', 'single') in namespace, locals 
    File "", line 7, in <module> 
IndexError: list index out of range 

것이 유용 ('bu')를 사용하여 무슨 일이 일어나고 있는지 감지하고 이해하려고 시도합니다.

,451,515,

편집 : 코드와

:

for i in range(0,len(max_faces_list)-2): 
    i 
    for j in range(i+1,len(max_faces_list)): 
     j 
     if max_faces_list[i].issubset(max_faces_list[j]): 
      print('bu') 
      print(i, F) 
      F.remove(F[i]) 
      break    

출력은 다음과 같습니다

0 
1 
2 
3 
4 
bu 
(0, [Simplicial complex with vertex set (0, 2, 3) and facets {(0, 2, 3)}, Simplicial complex with vertex set (0, 1, 2) and facets {(0, 1, 2)}, Simplicial complex with vertex set (1, 2, 3) and facets {(1, 2, 3)}, Simplicial complex with vertex set (0, 1, 3) and facets {(0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(1, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (1, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (1, 2, 3), (0, 1, 3)}]) 
1 
2 
3 
4 
bu 
(1, [Simplicial complex with vertex set (0, 1, 2) and facets {(0, 1, 2)}, Simplicial complex with vertex set (1, 2, 3) and facets {(1, 2, 3)}, Simplicial complex with vertex set (0, 1, 3) and facets {(0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(1, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (1, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (1, 2, 3), (0, 1, 3)}]) 
2 
3 
4 
5 
bu 
(2, [Simplicial complex with vertex set (0, 1, 2) and facets {(0, 1, 2)}, Simplicial complex with vertex set (0, 1, 3) and facets {(0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(1, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (1, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (1, 2, 3), (0, 1, 3)}]) 
3 
4 
5 
6 
bu 
(3, [Simplicial complex with vertex set (0, 1, 2) and facets {(0, 1, 2)}, Simplicial complex with vertex set (0, 1, 3) and facets {(0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(1, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (1, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (1, 2, 3), (0, 1, 3)}]) 
4 
5 
6 
7 
8 
9 
10 
bu 
(4, [Simplicial complex with vertex set (0, 1, 2) and facets {(0, 1, 2)}, Simplicial complex with vertex set (0, 1, 3) and facets {(0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(1, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (1, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (1, 2, 3), (0, 1, 3)}]) 
5 
6 
7 
8 
9 
10 
bu 
(5, [Simplicial complex with vertex set (0, 1, 2) and facets {(0, 1, 2)}, Simplicial complex with vertex set (0, 1, 3) and facets {(0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(1, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (1, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (1, 2, 3), (0, 1, 3)}]) 
6 
7 
8 
9 
10 
11 
bu 
(6, [Simplicial complex with vertex set (0, 1, 2) and facets {(0, 1, 2)}, Simplicial complex with vertex set (0, 1, 3) and facets {(0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(1, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (1, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (1, 2, 3), (0, 1, 3)}]) 
7 
8 
9 
10 
bu 
(7, [Simplicial complex with vertex set (0, 1, 2) and facets {(0, 1, 2)}, Simplicial complex with vertex set (0, 1, 3) and facets {(0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (1, 2, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(1, 2, 3), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (0, 1, 2), (0, 1, 3)}, Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 1, 2), (1, 2, 3), (0, 1, 3)}]) 
Error in lines 2-10 
Traceback (most recent call last): 
    File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1013, in execute 
    exec compile(block+'\n', '', 'single') in namespace, locals 
    File "", line 8, in <module> 
IndexError: list index out of range 

그래서 오류가 나는 더 이상 [i]는 F를 제거 할 수 있다는 것입니다. 이 점을 발견해 주셔서 감사합니다 @Akash Wankhede !! 나는 나의 실수를 이해했다고 생각한다!

+1

여기서 "F"변수의 값을 공유 할 수 있습니까? –

+0

done @AkashWankhede – D1811994

+1

"print ('bu')"바로 아래에이 문장 "print (i, F)"를 추가하고 출력을 공유 할 수 있습니까? –

답변

1

"print ('bu')"바로 아래에이 문장 "print (i, F)"를 추가하십시오.