Append data to a list within a dict

Michael Bentley michael at jedimindworks.com
Sat Apr 14 01:50:41 EDT 2007


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



More information about the Python-list mailing list