Guest User

Untitled

a guest
Jul 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. import time
  2.  
  3. start = time.clock()
  4.  
  5. def valid_char(c):
  6. return (c >= 'a' and c <= 'z')
  7.  
  8. words = set()
  9. total = 0
  10.  
  11. f = open('alice.txt', 'r')
  12. f = f.read().lower()
  13.  
  14. i = 0
  15. chars = len(f)
  16. while i < chars:
  17. word = ""
  18. while i < chars and not valid_char(f[i]):
  19. i+=1
  20. while i < chars and valid_char(f[i]):
  21. word = word + f[i]
  22. i+=1
  23. if len(word) > 0:
  24. total+=1
  25. if word not in words:
  26. words.add(word)
  27.  
  28. words = sorted(words)
  29.  
  30. end = time.clock()
  31.  
  32. print "chars: " + str(chars) + " distinct:" + str(len(words)) + " total:" + str(total) + " time:" + str( end - start)
Add Comment
Please, Sign In to add comment