I have a list of numbers say, [2,2,3,3,4,1] I want to sort by frequency and if the frequency count (ascending) is same then sort by value (also ascending). Soln would be [1,4,2,2,3,3]
For frequency
from collections import Counter
print sorted(arr, key=Counter(arr).get)
But I am not sure how to sort by value for same frequency count elements
sorted(l, key=lambda x: [l.count(x),x])- Sohaib FarooqiCounter. I was just trying to show OP how to use multiple keys to sort. - Sohaib Farooqi