Link to home
Start Free TrialLog in
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
ASKER CERTIFIED SOLUTION
Avatar of gelonida
gelonida
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jamie_lynn
jamie_lynn

ASKER

Works great! thanks!