| [ Web Proxy ] |
| Viewing: https://raw.githubusercontent.com/GHubPythonProjects/py4e/master/code2/count1.py | [Back] [Original] |
fname = raw_input('Enter the file name: ')
try:
fhand = open(fname)
except:
print 'File cannot be opened:', fname
exit()
counts = dict()
for line in fhand:
words = line.split()
for word in words:
if word not in counts:
counts[word] = 1
else:
counts[word] += 1
print counts
| Web Proxy Viewer | New URL | Original Page |