# [Tutor] anagrams

Gregor Lingl glingl at aon.at
Wed Nov 5 18:25:34 EST 2003

```Hi Karl!

Karl Pflästerer schrieb:

>On  5 Nov 2003, Gregor Lingl <- glingl at aon.at wrote:
>
>
>
>>Triggered by a remark on the DailyPythonUrl I looked for the
>>
>>
>
>
>

This is part of the pythonware website. It records new developments in the
world of Python. Have a look at it here:

http://www.pythonware.com/daily/

(There is also a link to it from the homepage of www.python.org
"Other items of interest", third link from the bottom.

Thanks for your code (both solutions).  I'll study them tomorrow
evening. It's now half past
midnight here (in Vienna) and I have to get up early in the morning.

Talk to you later
Regards,
Gregor

(P. S.: You seem to be from Deutschland? Right? From where?)

>
>
>>Kata - Site and found an interesting little problem: finding
>>anagrams among the words in a textfile.
>>
>>
>
>[...]
>
>
>>I found a Python Solution, which needs 0.75 secs on my 2.3 GHz PC,
>>but it certainly is not optimal. (Maybe someone here likes to find
>>a better one?)
>>
>>
>
>Don't know if mine one is better; on my PC it's 30% faster than your
>solution.
>
>
>
>>Another problem remains for me: My script finds 2531 groups
>>of anagrams with 5683 words alltogether, whereas the above
>>mentioned solution has only 2,530 sets of anagrams (and a total of
>>5,680 words). So I suspect, that my solution contains a bug, but
>>I couldn't find it (until now).
>>
>>
>
>My solution finds the same values as yours one.  Perhaps the bug is in
>the Ruby code?
>
>[Code]
>
>f = open("wordlist.txt")
>
>d = {}
>for word in f:
>    k, v = list(word.lower()), word
>    k.sort()
>    k = ''.join(k)
>    if k in d:
>        d[k].append(v)
>    else:
>        d[k] = [v]
>
>f.close()
>
>ang = [x for x in d.itervalues() if len(x) > 1]
>
>print len(ang)
>print sum([len(x) for x in ang])
>
>
>
>   Karl
>
>

```