Message303093
I think it is a good idea to have a simple way to add a value to sort on in general, it could have some interesting use-cases. Also I am with Nick a name change would make the broader scope clearer.
What I am not sure about is making the comparison have to be between two items of the same wrapper type - since right now we are comparing priority to priority attributes.
It makes sense for PriorityQueues, but if we wanted to use this for something more arbitrary like comparing a string with an int priority to an int we end up having to convert both data types to the new wrapper type:
str_cmp = KeyedItem(20, 'cat')
int_cmp = KeyedItem(30, 30)
str_cmp < int_cmp
I don't like having to convert to the new wrapper unless it's relevant, I'd rather do:
str_cmp = KeyedItem(20, 'cat')
str_cmp < 30
It could be instead:
class KeyedItem:
def __init__(self, key, item):
self.key = key
self.item = item
def __eq__(self, other):
if not isinstance(other, KeyedItem):
return self.key == other
return self.key == other.key
def __lt__(self, other):
if not isinstance(other, KeyedItem):
return self.key < other
return self.key < other.key
... |
|
Date |
User |
Action |
Args |
2017-09-27 04:44:50 | lisroach | set | recipients:
+ lisroach, rhettinger, ncoghlan, r.david.murray, Mikołaj Babiak |
2017-09-27 04:44:49 | lisroach | set | messageid: <1506487489.96.0.154975027568.issue31145@psf.upfronthosting.co.za> |
2017-09-27 04:44:49 | lisroach | link | issue31145 messages |
2017-09-27 04:44:49 | lisroach | create | |
|