If you want all words sorted by min value:
import numpy as np
list1 = ["cry", "me", "me", "no", "me", "no", "no", "cry", "me"]
list2 = ["cry", "cry", "cry", "no", "no", "no", "me", "me", "me"]
uniques_values = np.unique(list1)
final_list = []
for i in range(0,len(uniques_values)):
final_list.append((uniques_values[i], list1.count(uniques_values[i])))
def takeSecond(elem):
return elem[1]
final_list.sort(key=takeSecond)
print(final_list)
For list1:
[('cry', 2), ('no', 3), ('me', 4)]
For list2:
[('cry', 3), ('me', 3), ('no', 3)]
Be careful with the code, to change the list you have to edit the code in two points.
Some useful explanation:
numpy.unique gives you non-repeated values
def takeSecond(elem) with return elem[1], is a function which allows you to sort a array by the [1] column (the second value).
It could be useful to display values or get all items sorted by this criteria.
Hope it helps.