Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Denis McMahon Newsgroups: comp.lang.python Subject: Re: Building lists Date: Mon, 20 Oct 2014 22:40:50 +0000 (UTC) Organization: A noiseless patient Spider Lines: 20 Message-ID: References: <6jpa4ahhc8ln7hk8s0258hvqd3io51epa0@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Mon, 20 Oct 2014 22:40:50 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="66ffcfa4470a58bcddbdcd1913f98ab4"; logging-data="22967"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19e78AIgSXBPpU+b+SD6U1qIViyTTUaV+g=" User-Agent: Pan/0.136 (I'm far too busy being delicious; GIT 926a150 git://git.gnome.org/pan2) Cancel-Lock: sha1:ZfoETNEZXHVNdn/zsu9NW7Q7dl0= Xref: csiph.com comp.lang.python:79346 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@gmail.com