Friday, October 4, 2013

Little_Script_Series: Phyton version script Count number of Times 4 word on FILE

This is just an example with python with no checking the existence of the file or other and  i have to say that i found all of this over the INTERNET i just put the pieces together so there may be many other ways to do this.

At the beggining i tougth that python were not so good because i does not have any hash structure but it has many other it simplifies the perl version of course im talking of my franken_perl_version (:{

#  A Counter is a container that tracks how many times equivalent values are 

#  added.It can be used to implement the same algorithms for which other 
#  languages commonly use bag or multi-set data structures.

import sys;
from collections import Counter;
users = [];

for line in open(sys.argv[1], "r"):
  e = line.split();

  c = Counter(users);

for k in users:
  print '%s : %d' % (k, c[k]);

No comments:

Post a Comment