3 ms·
Right now I'm working on a large data set where there is a set of players and each player has a score. I'm using a Python dictionary from player ID to the play
by noaharc 18y ago
Right now I'm working on a large data set where there is a set of players and each player has a score. I'm using a Python dictionary from player ID to the player score, but I also want an easy way to grab the top N players from the set. The players' scores are updated continuously, so the quick mapping from a player ID to their updated score is also critical (if the scores were constant I'd just put it in a list, sort it, and be done with it).
- deleted 18y ago[deleted]
- deleted 18y ago[deleted]
- lacker 18y agoHmmm, does an ordered dictionary actually solve this problem? It seems like you want to retrieve based on player id, but get the top N based on score. An ordered dictionary would be ideal if you wanted to retrieve and get the top N based on the same key. I guess you could use two data structures, with one of them being an ordered dictionary. But then the ordered dictionary doesn't actually have to support lookup; you could just use a heap.