You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@goswami-rahul I was just seeing the function, and I wasn't able to figure out what will be the use of the __getitem__ function. Like we are giving value and getting that itself as output if it is there in the PriorityQueue. It means the same thing as __contains__ does i.e. to find if an element is there in the Queue or not. Instead of doing like this returning the value at an index would be better.
@sagar-sehgal The getitem function works quite differently than contains. We might just need both of them for different algorithms here.
Example:
Take two objects (a and b) of the same class, they will be stored as: ( f_val:1, id:1), (f_val:2, id:1). Here the same id implies that the objects are equal according to their eq function, but have a different f-value in the queue. Further, let us assume that a is in the queue and the second one isn't.
contains(b): Returns false! Because the f-value does not match that of a get_item(b): Returns a! Because they are equal according to their class definition and only their f-value differs.
It essentially returns the same
key
if it is present, else returns None (doesn't raise Exception).Is this the intended use?
Also, the documentation of PriorityQueue says
It supports dict-like lookup.
What exactly is the method
__getitem__
trying to do (and return)?The text was updated successfully, but these errors were encountered: