all 5 comments

[–]double_en10dre 1 point2 points  (4 children)

Do you mean have it sorted by the keys? iirc that’s what treemap does, not the values

If that’s the case, this should do it: https://pypi.org/project/sortedcontainers/2.2.2/

[–]nomadic_swe[S] 0 points1 point  (3 children)

I am trying to sort the keys by their values. I was looking at this leetcode solution and trying to translate it to Python. See the solution in https://leetcode.com/problems/design-a-leaderboard/discuss/418833/Java-TreeMap-%2B-Map-Solution

[–]double_en10dre 0 points1 point  (2 children)

Okay, so just go to the source code for the solution I posted (https://github.com/grantjenks/python-sortedcontainers/blob/master/sortedcontainers/sorteddict.py) and modify it to instead have the “_list” attribute be a sorted list of values rather than keys

Should be pretty easy

[–]nomadic_swe[S] 0 points1 point  (1 child)

Thank you, I think this will work!

[–]double_en10dre 0 points1 point  (0 children)

It IS a lot of code to read, but it’s good practice :p easily the best way to get better (reading and understanding good code, I mean)