Код: Выделить всё
parallel_sort([1,0,2],[{1:1},{0:0},{2:2}]) #[{0:0},{1:1},{2:2}]Код: Выделить всё
def parallel_sort(int_lst,dict_lst):
tuple_lst=[]
for i in range(len(int_lst)):
tuple_lst.append((int_lst[i],incomparable_class,dict_lst[i]))
tuple_lst.sort()
res=[]
for tupl in tuple_lst:
res.append(tupl[2])
return res
Код: Выделить всё
parallel_sort([1,0,2],[0,'0',[]]) #['0',0,[]]Код: Выделить всё
class Incomparable:
def __init__(self): #The incomparable class itself doesn't do anything
pass
def __eq__(self,obj): #Never equal to anything
return False
def __ne__(self,obj):
return True
def __gt__(self,obj): #Never greater than anything
return False
def __ge__(self,obj):
return False
def __lt__(self,obj): #Never lesser than anything
return False
def __le__(self,obj):
return False
Код: Выделить всё
incmp=Incomparable()
0incmp
#False
0==incmp
#False
incmp==incmp
#False
incmp!=incmp
#True
(0,incmp,0)(0,0,'0')
#True
#Up to here, it works as intended
(0,incmp,0)
Подробнее здесь: [url]https://stackoverflow.com/questions/79831990/issues-with-tuple-comparison-while-using-a-specific-class-that-bypasses-comparis[/url]
Мобильная версия