I am receiving on server objects from clients ( every object has same structure and have field self.utc_time which contains time of creation of that object). I need to store in some structure so I always have sorted in ascending so when I pop I pop the oldest object by utc_time, not by time when I receive. I thought to use priority queue from heapq but how to say to heaify by utc_time field from custom objects ? Is there better solution ?
Share
Add the magic
__cmp__comparison method to your class to avoid needing to do the tuple-decoration that Maksim describes:Python 3
Python 2
Code Runner:
Note: Override
__lt__in Python 3,__cmp__only in Python 2