"Douglas Philips" <d...@mac.com> wrote
for element in value:
lookup[element] = lookup.get(element, []).append(key)
# Doug: That doesn't do what you think it does, it won't insert the
new list into the dictionary.
Ah, yes I forgot append was one of those annoying python methods
that doesn't return self...
You need to do it in three lines... One to get the list,
one to append and one to assign the value...
# Doug: I think what you want is lookup.setdefault(element,
[]).append(key)
or use setdfault (which I forgot all about! :-)
Thanks for picking that one up Doug.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor