It is a script to check for duplicate character string elements in the list using Python and output the result as multiple elements in descending order. It is expressed in inclusion notation.
python
data = ['a', 'b', 'c', 'd', 'b', 'c', 'd', 'b', 'c', 'b']
result = sorted({i: data.count(i) for i in set(data)}.items(), key=lambda x: x[1], reverse=True)
print(result)
>>> [('b', 4), ('c', 3), ('d', 2), ('a', 1)]
Recommended Posts