Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def wordLengthStats(filename):
- file = open(filename, 'r')
- wordcount={}
- for line in file.read().split():
- if line not in wordcount:
- wordcount[line] = 1
- else:
- wordcount[line] += 1
- for k,v in wordcount.items():
- print (k, v)
- return None
- def main():
- d = wordLengthStats("sample.txt")
- print("d should be { 3:5, 4:2, 5:1, 8:1, 10:1} ")
- print("d is", d)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement