Building lists

Seymore4Head Seymore4Head at Hotmail.invalid
Mon Oct 20 18:44:37 EDT 2014


On Mon, 20 Oct 2014 22:40:50 +0000 (UTC), Denis McMahon
<denismfmcmahon at gmail.com> wrote:

>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.

Thanks



More information about the Python-list mailing list