Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103462

Re: Nested List question

From Grant Edwards <invalid@invalid.invalid>
Newsgroups comp.lang.python
Subject Re: Nested List question
Date 2016-02-24 21:14 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <nal6g6$6j3$1@reader1.panix.com> (permalink)
References <mailman.105.1456347598.20994.python-list@python.org>

Show all headers | View raw


On 2016-02-24, <grsmith@atlanticbb.net> <grsmith@atlanticbb.net> 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!!

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Nested List question <grsmith@atlanticbb.net> - 2016-02-24 15:59 -0500
  Re: Nested List question Grant Edwards <invalid@invalid.invalid> - 2016-02-24 21:14 +0000

csiph-web