I've been googling and seaching and I just cant find an answer.
I have a dictionary which holds the people in the group, and the score the group has, groups = {"john,alfred,willis":5, "james,connor":5}, ...
. People can be in 2 groups at once, however. What I want to do with this dictionary is sort it by the amount of people AND their score. For example:
>>> groups = {"a,b,c":5, "d,e":6, "f,g,h,i":5, "j,k,l":6, "m,n":10, "a,d,f":5}
I need to sort it by the score, then by the amount of people, and then by alphabetical order as a final tie breaker. There are no duplicates of groups, however one group may own "a,b,c,d"
and another may own "a,b,c,e"
. Higher score trumps lower score, more people trumps less people, and alphabetical order is ... alphabetical order.
>>> print(mySort(groups))
"m,n", 10
"j,k,l", 6
"d,e", 6
"f,g,h,i", 5
"a,b,c", 5
"a,d,f", 5
The output format doesn't have to be like that, but it is preferred that it is formatted in the way of a dictionary.
I have attempted a few different ways, including splitting the key by ,
's because the names can be of any length, but because Python isn't my first language, I'm finding it difficult.
How do you sort dictionaries by value and then key size?
EDIT: I have added another part to the question which I thought I could go without. Turns out it's needed though...