Append data to a list within a dict

Tina I tinaweb at bestemselv.com
Sat Apr 14 02:16:31 EDT 2007


Michael Bentley wrote:
> 
> On Apr 14, 2007, at 12:39 AM, Tina I wrote:
> 
>> Say I have the following dictionary:
>>
>> ListDict = {
>> 'one' : ['oneone' , 'onetwo' , 'onethree'],
>> 'two' : ['twoone' , 'twotwo', 'twothree'],
>> 'three' : ['threeone' , 'threetwo', threethree']}
>>
>> Now I want to append 'twofour' to the list of the 'two' key but I can't
>> figure out how to that?
>> Some pointers would be greatly appreciated.
> 
> ListDict['two'].append('twofour')
> 
> But you'll have to insert the missing single quote before "threethree" 
> first.
> 
> hope this helps,
> Michael
Great! Thanks!
And the missing singlequote was just a typo, my actual dictionary is way 
bigger so I just made up this as an example.

Tina



More information about the Python-list mailing list