+ 1

Compare function does not work, Why?

list1 = [1,2,3] list2 = [4,5,6] print (list1) print (list2) print (cmp(list1,list2)) Output: [1, 2, 3] [4, 5, 6] Traceback (most recent call last): File "python", line 5, in <module> NameError: name 'cmp' is not defined

16th Mar 2017, 12:27 PM
suraj jadhav
suraj jadhav - avatar
4 Réponses
+ 1
In python 3 there was no cmp module in it . so you need to do this by your self. you can try this .. def cmp(a,b): return (a>b) - (a<b) it gives same result
16th Mar 2017, 12:49 PM
Rohan Vijayvergiya
Rohan Vijayvergiya - avatar
0
why is it removed?
16th Mar 2017, 12:50 PM
suraj jadhav
suraj jadhav - avatar
0
dont know but they have to change something.from python 2
16th Mar 2017, 12:51 PM
Rohan Vijayvergiya
Rohan Vijayvergiya - avatar
0
thanks
16th Mar 2017, 12:54 PM
suraj jadhav
suraj jadhav - avatar