파이썬/파이썬 일반 꿀팁
파이썬 리스트 끼리의 대소비교
주인장 아저씨
2022. 8. 2. 01:34
num_1=[2,8,3,4,5]
num_2=[4,6,3,1,3]
class comparable_list(list):
def __lt__(self, other):
return all(x < y for x, y in zip(self, other))
def __gt__(self, other):
return all(x > y for x, y in zip(self, other))
n1 = comparable_list(num_1);
n2 = comparable_list(num_2);
print(n1 < n2) # False
n3 = comparable_list([9,9,9,9,9]);
print(n1 < n3) # True
n4 = comparable_list([0,0,0,0,0]);
print(n1 > n4) # True