• Getting the sorting right

Question related to mission Sort Array by Element Frequency

 

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]