Advertisement
elcocodrilotito

a) histograma inverso

Dec 12th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. def histograma_inverso(archivo):
  2.     d=dict()
  3.     fp=open(archivo+".txt")
  4.     linea=fp.readline()
  5.     while linea:
  6.         for i in linea.split():
  7.             if i in d:
  8.                 d[i]+=1
  9.             else:
  10.                 d[i]=1
  11.         linea=fp.readline()
  12.     d2=dict()
  13.     for i in d:
  14.         if d[i] in d2:
  15.             d2[d[i]].append(i)
  16.         else:
  17.             d2[d[i]]=[i]
  18.     return d2
  19.  
  20. print(histograma_inverso("palabras diferentes"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement