Light Mode
Dark Mode
Getting the sorting right

Hello!

So I'm wondering how to get this to sort them with the proper grouping, because the code below returns the first set with the 2's in between the 6's. I expect I'll need to add more in later to find a way to cope with the empty list, but at the moment I'm wondering what the easiest way to get it to have the right kind of grouping would be.

def frequencysort(items): newlist = sorted(items, key= items.count, reverse=True) return new_list

Example: [4, 4, 4, 4, 6, 2, 2, 6]

Created: Jan. 5, 2020, 11:52 p.m.
Updated: Oct. 22, 2021, 10:10 p.m.
0
5
User avatar
Noith