danilobellini

Less lines of code (PythonBrasil[10])

Jun 19th, 2014
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. from itertools import groupby
  4.  
  5. with open("massa.txt") as fobj:
  6.     lasts = (line.rsplit(".", 1)[-1].strip() for line in fobj.readlines())
  7.     groups = groupby(sorted(lasts))
  8.     items = ((sum(1 for el in group), ext) for ext, group in groups)
  9.     for item in sorted(items, reverse=True):
  10.         print("%3d %s" % item)
  11.  
  12. # Based on https://www.facebook.com/pythonbrasil/photos/a.582882565067606.1073741825.328258703863328/776054062417121/
Advertisement
Add Comment
Please, Sign In to add comment