Building lists

Denis McMahon denismfmcmahon at
Tue Oct 21 00:40:50 CEST 2014

On Mon, 20 Oct 2014 15:49:15 -0400, Seymore4Head wrote:

> For starters I would like to know if you can make a single item list and
> then turn it into a 2 item list.  Is there a command for that?

Yes, it's called assignment. You can for example change a member of a 
list from an string to a tuple such as ( string, number ):

>>> x = [ "fred", "jim", "susan" ]
>>> x[x.index("jim")] = ( "jim", 11, )
>>> print x
['fred', ('jim', 11), 'susan']

> Do you have to know the number of items the list will have before making
> it?

No. See the append() method of the list object.

Denis McMahon, denismfmcmahon at

More information about the Python-list mailing list