2014-11-02 5 views
0

distanceorder 거리의 수치 정렬이 나 별도리스트와 동일한 값이 목록 내의 값의 인덱스를 얻으려면Python;

for i in range(0, len(distance)): 
    if distanceorder[i]==distance[i]: 

     RA_order[i]=RA[i] 
     DEC_order[i]=DEC[i] 
     epoch_order[i]=epoch[i]     

    else: 
     x=distance.index("distanceorder[i]") 
     RA_order[i]=RA[x] 
     DEC_order[i]=DEC[x] 
     epoch_order[i]=epoch[x] 

오류 ValueError를 함께 붙어 'distanceorder가 [I]'일 목록에 없음 해당 거리와 함께 주문 된 RA, DEC 및 신기원이 필요합니다.

+0

인용문은 무엇입니까? 'distance.index (distanceorder [i])'를 원하지 않니? – jonrsharpe

답변

0

구문

x=distance.index("distanceorder[i]") 

에 대체 잘못
x=distance[index(distanceorder[i])] 

당신의 거리가 목록 유형, 당신은 따옴표에 넣어 경우, 그것은 distanceorder[i]의 가치를 평가하지 않기 때문에 당신이 오류가 발생하는 이유 인 경우 대신 distanceorder[i]의 색인을 찾습니다. 먼저 인용 부호없이 값을 얻습니다. distanceorder[i]

0

endx = distance.index (distanceorder [i])

그러나 새로운 목록 RA_order의 크기를 무제한으로 지정해야하므로 무한대로 검색하여 답변을 얻고 자했습니다.