2017-06-16 11 views
-4
def compare(a,b): 
    if a == b: 
     return True 
    else: 
     return False 

While(f == 0): 

    if(compare(newk1,k1)==True): 
     if(compare(newk2,k2)==True): 
      f=1 
      break 
     else: 
      f=0 
    else: 
     f = 0 
    k1 = newk1 
    k2 = newk2 

エラー同じインデックスとpythonで二つのリストに一致する

File "C:\Users\..\Desktop\problem_solution.py", line 101, in <module> if(compare(newk1,k1)==True): 
File "C:\Users\..\Desktop\problem_solution.py", line 25, in compare if a == b: 
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() 
+5

範囲(0,3)に私のためのあなたの努力 – kuro

+0

をご提示ください: I K1でnewk1と私であれば: newk1.index(I)==はk1.index(I)の場合: //ものを行います –

+0

@ShreyGuptaコメントは編集していません。 – WhatsThePoint

答えて

0

私のための範囲(0、LEN(K1))に:

if(newk1[i] == k1[i]).all 
    return True 
else: 
    return False 

これが問題を解決します。

0

物事を複雑にする必要はありません:

if list1 == list2: 
    print "Equal" 
else: 
    print "Not equal" 
関連する問題