Nested List question

Grant Edwards invalid at invalid.invalid
Wed Feb 24 16:14:46 EST 2016


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


More information about the Python-list mailing list