# A function that returns the frequency of each value:
def myFunc(e):
return cars.count(e)
cars = ['Ford', 'Ford', 'Ford', 'Mitsubishi','Mitsubishi', 'BMW', 'VW']
cars.sort(key=myFunc)
print(cars)
Output:
['Ford', 'Ford', 'Ford', 'Mitsubishi', 'Mitsubishi', 'BMW', 'VW']
What I expect:
['BMW', 'VM', 'Mitsubishi', 'Mitsubishi', 'Ford', 'Ford', 'Ford']
Counts:
Ford - 3
Mitsubishi - 2
BMW - 1
VM - 1
It should sort in ascending order of count in the list.