Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. def wordLengthStats(filename):
  2. file = open(filename, 'r')
  3. wordcount={}
  4. for line in file.read().split():
  5. if line not in wordcount:
  6. wordcount[line] = 1
  7. else:
  8. wordcount[line] += 1
  9. for k,v in wordcount.items():
  10. print (k, v)
  11. return None
  12.  
  13. def main():
  14.  
  15. d = wordLengthStats("sample.txt")
  16. print("d should be { 3:5, 4:2, 5:1, 8:1, 10:1} ")
  17. print("d is", d)
  18.  
  19. if __name__ == '__main__':
  20. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement