[melbourne-pug] Fun with phononyms

Tennessee Leeuwenburg tleeuwenburg at gmail.com
Mon Aug 17 05:15:21 CEST 2009


Cool, I didn't know about maketrans. Thanks.

I always wish setdefault looked a little nicer, but it's such a great
defensive programming technique that I just use it anyway.

Thanks for kicking the discussion off, M. Nice to see some chatter on the
list at last! :)

Cheers,
-T


On Mon, Aug 17, 2009 at 1:09 PM, John La Rooy <john.larooy at gmail.com> wrote:

> This is how I would do it.
>
> #!/usr/bin/env python
> from string import maketrans
>
> dictionary = "sowpods.txt"
> nokia =
> maketrans("abcdefghijklmnopqrstuvwxyz","22233344455566677778889999")
> phononyms = {}
>
> for word in open(dictionary):
>     word = word.strip().lower()
>    phononyms.setdefault(word.translate(nokia), []).append(word)
>
> for k,v in phononyms.iteritems():
>    if len(v) > 1:
>        print v
> _______________________________________________
> melbourne-pug mailing list
> melbourne-pug at python.org
> http://mail.python.org/mailman/listinfo/melbourne-pug
>



-- 
--------------------------------------------------
Tennessee Leeuwenburg
http://myownhat.blogspot.com/
"Don't believe everything you think"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/melbourne-pug/attachments/20090817/c3bf2aaf/attachment.htm>


More information about the melbourne-pug mailing list