Alan Gauld <alan.gauld <at> btinternet.com> writes: > > On 04/12/13 10:22, Wolfgang Maier wrote: > > > > > # instead of senateInfo[lastName] = state, > > # which builds a simple state dictionary > > if lastName in senateInfo: > > senateInfo[lastName].append((firstName, state)) > > else: > > senateInfo[lastName] = [(firstName, state)] > > Or replace those last four lines with > > senateInfo[lastName] = senateInfo.get( > lastName,[]).append((firstname,state)) >
Right, forgot to mention your shorter alternative, Alan. Sorry about that. Personally, I find the four-liner easier to explain (specially to beginners), but I guess that's a matter of style and, of course, the one-liner introduces the generally useful get method. Wolfgang _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor