The other day I noticed that the words ‘kiss’ and ‘lips’ (don’t ask) could be spelled on the same buttons when texting on a phone. I idly wondered what other related words could be spelled on identical buttons. That idle wondering festered in my brain and eventually turned in to a Python script (which is often the result of my wonderings). The script I wrote, groups words together by the sequence of phone buttons needed to txt them. It also filters out sequences with just one word, which I wasn’t interested in. Here is the code:
txt_words = {}
def to_number(c):
return "22233344455566677778889999"[ord(c)-ord('a')]
for line in file("word.lst"):
word = line.rstrip()
txt_word = "".join(to_number(c) for c in word)
if txt_word not in txt_words:
txt_words[txt_word] = []
txt_words[txt_word].append(word)
def cmp_word_lengths(w1, w2):
return cmp(len(w1), len(w2))
out = file("txtwords.txt", "w")
for txt_word in sorted(txt_words.keys(), cmp=cmp_word_lengths):
if len(txt_words[txt_word]) == 1:
continue
print >> out, "[%s] %s" % (txt_word, ", ".join(txt_words[txt_word]))
Next I scanned through the output to find related words. I guess this could be done automatically if I had access to a thesaurus file, but that seemed more trouble that it is worth. Here are a few I picked out…
[24453] AGILE CHILD - A fast moving kid?
[54779] KISSY LIPPY - Pucker up.
[74353] RIFLE SHELF - Were you keep your rifles.
[874353] TRIFLE UPHELD - A British desert, held up.
[766643] POMMIE ROOMIE - Its what Australians call their English room-mates.
In addition to the related words I found, there was also a few combinations that I found amusing, in a low-brow kind of a way.
[28789] BUSTY CURVY - Stop, I’m blushing.
[77265] SPANK PRANK - Don’t do it, it’s harassment.
[746633] RIMMED SINNED - Pretty sure it’s a sin.
I’m tired of looking. If you find any more good ones, let me know!
Additional: You will need the word list if you want to play with the code.