Can any body help me

Tim Chase python.list at tim.thechases.com
Fri May 26 08:48:51 EDT 2006


> 1.Given a test file containing lines of words such as (abc, abb,
> abd,abb, etc), write a script that prints, in order of frequency, how
> many times each word appears in the file.

solution 1)  search the list archives...within the last week, 
someone wanted to count unique lines in an input file.  Several 
solutions were given--one of which solved it by counting 
instances of each unique line using a set.  The resulting 
dictionary can then be sorted (by key or value) to yield your 
desired results.  Tweak accordingly.

solution 2)  using common *nix shell commands:

	bash$ sort in.txt | uniq -c | sort -nr

-tkc







More information about the Python-list mailing list