I want the black one… Wait, can it be used as a modem? I hope so…
Edit: I probably won’t be able to afford it still, but what the heck. I can dream, can’t I?
1 month agoJust a quick hack…
#!/usr/bin/env python2.5
#
# Copyright (C) 2008 Aldous D. Penaranda <aldous@penaranda.name>
# Written using the default Python interpreter on Mac OS X 10.5.3
#
import random
import re
import sys
def is_vowel(letter):
if letter.lower() in "aeiou":
return True
def spellcheck(dict, misspelled):
count = 0
prev = misspelled[0]
regex = "^"
misspelled = misspelled + "_"
for i in misspelled:
if prev == i:
count = count + 1
else:
if is_vowel(prev):
regex = regex + "[aeiou]"
else:
regex = regex + prev.lower()
if count == 1:
pass
else:
regex = regex + "{1," + str(count) + "}"
count = 1
prev = i
regex = regex + "$"
result = []
r = re.compile(regex, re.I)
for i in dict:
m = r.match(i)
if m:
result.append(m.group(0))
if misspelled == m.group(0):
result = [m.group(0)]
break
if result == None:
return None
elif len(result) > 1:
return result[random.randint(0, len(result)-1)]
elif len(result) == 1:
return result[0]
else:
return None
if __name__ == "__main__":
f = open("/usr/share/dict/words")
words = f.readlines()
buckets = {}
for i in "abcdefghijklmnopqrstuvwxyz":
buckets[i] = []
for word in words:
word = word.strip()
buckets[word[0].lower()].append(word)
while True:
input = raw_input("> ")
suggestion = spellcheck(buckets[input[0].lower()], input)
if not suggestion:
print "NO SUGGESTION"
else:
print suggestion
1 month ago