[Tutor] need a hint

Alan Gauld alan.gauld at btinternet.com
Mon Dec 2 20:30:29 CET 2013


On 02/12/13 15:18, Wolfgang Maier wrote:

>>> You can do so by turning the entries in senateInfo from a list of strings
>>> (states) into a list of tuples (first name, state) like this:
>>>
>>>       senateInfo[lastName] = [(firstName, state)]
>>>
>>> or for pre-existing entries:
>>>
>>>       senateInfo[lastName].append((firstName, state))
>>
>> This results in a mixed set of values for your dictionary. Some will be
>> simple strings (or tuples), others lists of tuples. You might want to

> maybe you misread my code snippet?? It generates lists all the time just as
> you are suggesting (same as for Oscar's).

Oops, yes, I misread, sorry.

But using get() still helps in that it removes the need to check whether 
the entry already exists. So you only need one method of
entry.

But my initial point was wrong so apologies about that.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list