Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What about dictionaries sorted by value? #146

Closed
matteodellamico opened this issue May 11, 2020 · 4 comments
Closed

What about dictionaries sorted by value? #146

matteodellamico opened this issue May 11, 2020 · 4 comments

Comments

@matteodellamico
Copy link

Hi!

Unless I'm missing something, sortedcontainers doesn't support dictionaries sorted by value. This is useful to implement priority queues (à-la heapq) where an item's priority can change over time. For example, graph algorithms (e.g., Dijkstra's algorithm for shortest paths) benefit from this. Here's an old Python cookbook recipe of mine for something like that (based, in turn, on an idea by David Eppstein): http://code.activestate.com/recipes/522995-priority-dict-a-priority-queue-with-updatable-prio/ .

I wonder if sortedcontainers would be a good place to put a similar container in a widely used library.

@grantjenks
Copy link
Owner

The data type is in the sortedcollections library and is based on sortedcontainers: http://www.grantjenks.com/docs/sortedcollections/valuesorteddict.html

@grantjenks
Copy link
Owner

See also #110

@matteodellamico
Copy link
Author

Wow, I discover now sortedcollections. Thanks!

@grantjenks
Copy link
Owner

Also dupe of #57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants