On 2011/10/28 11:51 AM, Albert-Jan Roskam wrote:
It would be nice to generalize the solution so it could also handle
definitions={"Deprecated": "No longer in use", "DEPRECATED": "No longer in use"}
These are unique now, but after turning them into lower case not anymore.
new_d = {}
for d in definitions:
    try:
        new_d[d.lower()].append(definitions[d])
    except TypeError:
        new_d[d.lower()] = [definitions[d]]
Cheers!!
Albert-Jan


<snip>


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
To save yourself the try/except you can use defaultdict which is part of the collections module.

from collections import defaultdict
new_d = defaultdict(list)
for key, value in definitions.iteritems():
    new_d[key.lower()].append(value)

--

Christian Witts
Python Developer

//
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to