Path: csiph.com!weretis.net!feeder6.news.weretis.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!newsfeed-00-ls.mathworks.com!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: Nested List question Date: Wed, 24 Feb 2016 21:14:46 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 57 Message-ID: References: NNTP-Posting-Host: 67-130-15-94.dia.static.qwest.net X-Trace: reader1.panix.com 1456348486 6755 67.130.15.94 (24 Feb 2016 21:14:46 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Wed, 24 Feb 2016 21:14:46 +0000 (UTC) User-Agent: slrn/1.0.2 (Linux) Xref: csiph.com comp.lang.python:103462 On 2016-02-24, wrote: > All, > > Can you have a phython list like: > ['George', > 'Soros', > ['99 First Street', > '33 Broadway Avenue', ['Apt 303'], > '1 Park Avenue'], > 'New York', 'NY'] Sure: $ python3 Python 3.4.3 (default, Feb 12 2016, 15:58:12) [GCC 4.9.3] on linux Type "help", "copyright", "credits" or "license" for more information. >>> ['George', ... 'Soros', ... ['99 First Street', ... '33 Broadway Avenue', ['Apt 303'], ... '1 Park Avenue'], ... 'New York', 'NY'] ['George', 'Soros', ['99 First Street', '33 Broadway Avenue', ['Apt 303'], '1 Park Avenue'], 'New York', 'NY'] > In other words how do you correctly nest the > ['Apt 303'] so it goes with 33 Broadway Avenue. I'm afraid I don't know what you mean by "goes with". > Also, I tried several ways and could not figure out how to get the > ['Apt 303'] out of the list. How can you do that. Use the "del" operator: >>> foo = ['George', ... 'Soros', ... ['99 First Street', ... '33 Broadway Avenue', ['Apt 303'], ... '1 Park Avenue'], ... 'New York', 'NY'] >>> foo ['George', 'Soros', ['99 First Street', '33 Broadway Avenue', ['Apt 303'], '1 Park Avenue'], 'New York', 'NY'] >>> del foo[2][2] >>> foo ['George', 'Soros', ['99 First Street', '33 Broadway Avenue', '1 Park Avenue'], 'New York', 'NY'] > It is the ['Apt 303'] that is the problem, I know how to do the > other elements. I don't think I understand what your problem is. -- Grant Edwards grant.b.edwards Yow! I feel like I'm at in a Toilet Bowl with a gmail.com thumbtack in my forehead!!