Wordcount 1.2 
Yet more tweaking of my wee python script.

It can now take the variable from the command line.

$ python wordcount.py <file>




#! /usr/bin/python
import sys


def wordcount(a):
""" Wordcount will count how many instances there are of a word in a string, a. """
memory = [] # create memory
a = a.lower().split()

for i in a:
if i not in memory:
print "There are %(number)i instances of \" %(word)s \"\
in the string" % {"number": a.count(i), "word": i}
memory.append(i)

file = sys.argv[1]
a = open(file, "r").read()

wordcount(a)


[ add comment ] ( 1 view )   |  permalink

<<First <Back | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Next> Last>>