Avatar of jamie_lynn
jamie_lynn asked on

What is the best way to sort on frequency?

Hi
What is the best way to sort on frequency?

ie.
I want to sort the list below based on the frequency of the key of the dictionary.
There are four elements with "c" as the key so elements with "c" goes to the top.
then "a", then "b"
 list = [
        { "a": "a1"  },
        { "b": "b1"  },
        { "c": "c1"  },
        { "a": "a2"  },
        { "a": "a3"  },
        { "c": "c2"  },
        { "c": "c3"  },
        { "c": "c4"  },
        { "b": "b2"  }
     ]

Open in new window

sorts to
 list = [
        { "c": "c1"  },
        { "c": "c2"  },
        { "c": "c3"  },
        { "c": "c4"  },
        { "a": "a1"  },
        { "a": "a2"  },
        { "a": "a3"  },
        { "b": "b1"  },
        { "b": "b2"  }
     ]

Open in new window


Thanks
Jamie
Python

Avatar of undefined
Last Comment
jamie_lynn

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
gelonida

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
jamie_lynn

Works great! thanks!
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck