Edit- I have seen answers to other questions that explained how to sort dictionaries by keys or values, but didn't see any that allowed access to both the key and the value. Apologies if I did anything wrong, I'm obviously new here. Someone edited out the thanks at the end of my post which seems odd to me, but if I'm not supposed to do that in my posts, it'd be great if someone would let me know
I'm working on a personal project of being able to enter scoring settings for a fantasy baseball league into a program, and receiving a list of players and the point total they would have under that certain scoring system. I did some work with reading files containing totals from different scoring categories and calculated point totals based on the settings the user inputs. I then add the information to a dictionary where a string of the player's name, team, and position are the key, and their point total is the value. Here's the first few entries in the dictionary:
{'Rick Porcello, Bos SP': 579.0, 'Chris Sale, CWS SP': 575.0, 'Justin Verlander, Det SP': 601.0, 'Madison Bumgarner, SF SP': 617.0, 'Max Scherzer, Wsh SP': 668.0, 'Johnny Cueto, SF SP': 584.0}
I'm now looking for a way to display the contents of the dictionary sorted from greatest to least point totals. For example, I'd like to display the above entries as:
'Max Scherzer, Wsh SP': 668.0
'Madison Bumgarner, SF SP': 617.0
'Justin Verlander, Det SP': 601.0
'Johnny Cueto, SF SP': 584.0
'Rick Porcello, Bos SP': 579.0
'Chris Sale, CWS SP': 575.0
I'm aware of the sorted function for dictionaries, but that has left me with only a list of the point totals. Is there a way where I can sort the entries based on the values but still be able to access the keys so I know which player scored X points?
Additionally, if there is a function that allows me to do what I'd like, how does that function scale? I'd assume a function even with a bad complexity would be fine with just a few entries, but my full dictionary will have hundreds of players. This is just a personal project, so if I have to wait a minute to get the results, that's not a big deal, but obviously faster is better. I'm more just curious on this part, as the ability to do so regardless of the overall speed is my main concern.