[Python] TypeError: < not supported between instances of Node and Node

TypeError: '<' not supported between instances of 'Node' and 'Node'

PriorityQueue에 객체를 넣으려 하는데 위와 같은 에러 발생

🔎 원인

객체의 정렬 기준을 모르기 때문!

😇 해결

class Node:
    def __init__(self, level, weight, profit, bound, include):
        self.level = level
        self.weight = weight
        self.profit = profit
        self.bound = bound
        self.include = include

    def __lt__(self, other):
        return self.bound < other.bound

위 코드의 L59-60 과 같이 대소비교 메서드를 추가하면 된다.

참조 : https://www.daleseo.com/python-lt-not-supported/

© 2020 euzl. from JunhoBaik's, Built with Gatsby