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


Groups > comp.lang.python > #103459 > unrolled thread

Nested List question

Started by<grsmith@atlanticbb.net>
First post2016-02-24 15:59 -0500
Last post2016-02-24 21:14 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  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

#103459 — Nested List question

From<grsmith@atlanticbb.net>
Date2016-02-24 15:59 -0500
SubjectNested List question
Message-ID<mailman.105.1456347598.20994.python-list@python.org>
All,

Can you have a phython list like:
['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.

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. It is the ['Apt 303'] that is the problem,
I know how to do the other elements.

thanks
George 

[toc] | [next] | [standalone]


#103462

FromGrant Edwards <invalid@invalid.invalid>
Date2016-02-24 21:14 +0000
Message-ID<nal6g6$6j3$1@reader1.panix.com>
In reply to#103459
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!!

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web