troubleshooting Question

What is the best way to sort on frequency?

Avatar of jamie_lynn
jamie_lynn asked on
Python
2 Comments1 Solution416 ViewsLast Modified:
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"  }
     ]
sorts to
 list = [
        { "c": "c1"  },
        { "c": "c2"  },
        { "c": "c3"  },
        { "c": "c4"  },
        { "a": "a1"  },
        { "a": "a2"  },
        { "a": "a3"  },
        { "b": "b1"  },
        { "b": "b2"  }
     ]

Thanks
Jamie
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros