title: Custom comparator in Python
body: <p>I'm trying to write a custom comparator in Python, that compares two node objects based on the following rules
  1. Least frequency
  2. Shortest length
  3. Lexicographic ordering.</p>
  
  <p>Here's my node object</p>
  
  <pre><code>class Node:
      def __init__(self, key: str, value: int):
          self.key = key
          self.value = value
  </code></pre>
  
  <p>This is my Comparator</p>
  
  <pre><code>class Comparator:
      def __init__(self, node):
          self.node = node
  
      def __lt__(self, other):
          if self.node.value &gt; other.value:
              return True
          elif len(self.node.key) &gt; len(other.key):
              return True
          elif self.node.key &gt; other.key:
              return True
  </code></pre>
  
  <p>I'm trying to use this Comparator to push node items to a heap, this is my code,</p>
  
  <pre><code>frequency_map = Counter(string)
          for k, v in frequency_map.items():
              p = Node(k, v)
              heapq.heappush(self.heap, Comparator(p))
  </code></pre>
  
  <p>This throws up the following error,</p>
  
  <pre><code>AttributeError: 'Comparator' object has no attribute 'value'
  </code></pre>
  
  <p>What am I doing wrong here?</p>