I know this is a homework question, but I have reached the end of my rope and really need guidance. I have had four years of Java programming then walked into my CS 3 class and was given an assignment in python. I have never worked in Python before but tried writing some sample programs that seemed to work OK, but this project just won't cooperate. We have a text file(the Gettysburg Address) and we have to read it from sys.stdin into a dictionary which is to be sorted and have each word only once as the key with the word count for the value, then print out the dictionary. What I have is:
import sys
word_dictionary = {}
l = []
m = []
for s in sys.stdin:
l = s.split() #split the line into a list of words
for i in l:
m.append(i) #add elements of l to m since l will be overwritten
for j in m:
j.strip(' ,.?!')
j.lower()
m.sort()
for k in m:
if k in word_dictionary:
word_dictionary[k]=word_dictionary[k]+1
else:
word_dictionary[k]=1
for word in word_dictionary:
print word,word_dictionary[word]
However when I run this(python lab1.py getty.txt) nothing happens. If I put a print statement at the top where I initialize the lists and dictionary, it gets printed, but no other print statements are reached. Is there something wrong with my code? Or is my computer just really slow at reading the text file? Any help for an absolute novice?