Sep-06-2020, 02:00 PM
(Sep-06-2020, 01:54 PM)ndc85430 Wrote: That's GREAT, but how can I sort the final list according to the number of occurrences?you can use
most_common()
method of Counter:Quote:Return a list of the n most common elements and their counts from the most common to the least. If n is omitted or None, most_common() returns all elements in the counter. Elements with equal counts are ordered in the order first encountered:
from collections import Counter with open('dupes.csv', "r") as f: for name, name_count in Counter(f).most_common(): print(f'{name.strip()}:{name_count}')
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs