>>> text = ['1', '12', '123', '11', '1', '12', '12']
>>> from collections import Counter
>>> text_counts = Counter(text)
>>> text_counts
Counter({'12': 3, '1': 2, '11': 1, '123': 1})
>>> top_two = text_counts.most_common(2)
>>> top_two
[('12', 3), ('1', 2)]
$fruits = array("orange", "lemon", "apple", "orange", "banana", "orange", "apple");
$ratingFruits= array_count_values($fruits);
asort($ratingFruits);
print_r($ratingFruits);
{1: 7, // 1 в 1, 12, 123, 11, 1, 12, 12
12: 4,
etc}
?{12: 3,
1: 2,
etc}
?from collections import OrderedDict
d = map(str,[1,12,123,11,3,12,12])
OrderedDict(sorted({i: len([j for j in d if j.startswith(i)]) for i in d}.items(), key=lambda x: x[1], reverse = True))
OrderedDict(sorted({i:d.count(i) for i in d}.items(), key=lambda x: x[1], reverse=True))