Rotonym, what the heck is a rotonym?

Rotonyms are words that ROT-13 in to other words. I discovered the term from this site, which I found during my morning Reddit session. I think the author invented the term, because the only reference I found to 'rotonym' came from his site. Long story short, I knocked […]

Rotonym, what the heck is a rotonym?

Rotonyms are words that ROT-13 in to other words. I discovered the term from this site, which I found during my morning Reddit session. I think the author invented the term, because the only reference I found to 'rotonym' came from his site. Long story short, I knocked out a Python script to find all the rotonyms, given a list of words (just for the heck of it). I like problems like this. Its like the kind of work you had to do in high school and uni, before you enter the real word of programming and discover that most problems have blurry definitions and its hard to tell if your solution actualy works in all cases. Here's the code, let me know if you have a better solution.

If you want to run it, you will need this word list. Its not the most interesting code you will see, but I was impressed at how much functionality Python squeezes in to each line, without making it too obfusticated. It would be interesting to see this solved in other languages for comparison.

Update: fs111 reminded me that there was a rot13 string encoding in Python. So the code becomes:

>>> words = set([w.strip().decode('ascii', 'ignore') for w in file('/usr/share/dict/words')])>>> print [(w, w.encode('rot13')) for w in words if w.encode('rot13') in words]

First line reads the dictionary while ignoring unicode encoding errors (unfortunately necessary on my Ubuntu system). Second line gets the rotonyms (I don't like the duplicated encode() call in that line).

Something similar to Corey and Christian's solutions. The list of words could be a frozen set, because we don't have to mutate it. The 2nd list of rot13 words need not be a set, since we we just iterate over it. This is 2 or 3 lines long, depending on how you look at it :)

Jeethu, the change to frozenset is superfluous in this case, it doesn't gain anything. However, all you've managed to do is add back the python-land conditional that Christian's example employed. Using the set intersection (&) to sort out which ROTs are words is much more efficient.