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

Calendar



