Advertisement
Guest User

Untitled

a guest
Feb 21st, 2024
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. from pathlib import Path
  2. from collections import defaultdict
  3.  
  4. mapping = defaultdict(int)
  5.  
  6. with Path("chatmgs212.txt").open("rb") as file:
  7.     for line in file:
  8.         mapping[line.strip()] += 1
  9.  
  10. with Path("how_manymgs21.txt").open("wb") as file:
  11.     vals = sorted([(v,k) for k,v in mapping.items()],reverse=True)
  12.     file.writelines([f"{n} - {v}: {k.decode()}\n".encode() for n,(v,k) in enumerate(vals,start=1)])
  13.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement