Avatar ·

The frequency of words in those

📁 исключение, python, вопрос, пример, работа

The above script on Python calculates the frequency of words in the text (continuous sequences of letters with the exception of punctuation marks) and displaying the results of the results.

it works correctly. The question is what: is it possible to do the same easier (for example, less lines of code) on Python, Bash, PHP, Perl or is it the best way?

  Import Sysimport  string  file =  open  (sys.argv [ 1 ], ) text = file.  Read  () file.  clause  ()   table  =  string  .maketrans ( "" "" , ) words = text.  lower  (). Split (none) frequencies = {}   for  word  in  buts:  trimmed = word.translate ( table ,  string  .punctowation)  frequencies [trimmed] = frequencies.get (trimmed,  0 ) +  1  keys = sorted (frequencies.keys ())   for  word  in  keys:   print  "%"%-32s-32s-32s % D ""  % (Word, Frequencies [Word])