"Douglas Philips" <[email protected]> wrote
# Doug: That doesn't do what you think it does, it won't insert the new list into the dictionary.for element in value:lookup[element] = lookup.get(element, []).append(key)
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 - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
