Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- start = time.clock()
- def valid_char(c):
- return (c >= 'a' and c <= 'z')
- words = set()
- total = 0
- f = open('alice.txt', 'r')
- f = f.read().lower()
- i = 0
- chars = len(f)
- while i < chars:
- word = ""
- while i < chars and not valid_char(f[i]):
- i+=1
- while i < chars and valid_char(f[i]):
- word = word + f[i]
- i+=1
- if len(word) > 0:
- total+=1
- if word not in words:
- words.add(word)
- words = sorted(words)
- end = time.clock()
- print "chars: " + str(chars) + " distinct:" + str(len(words)) + " total:" + str(total) + " time:" + str( end - start)
Add Comment
Please, Sign In to add comment