you can indeed have a nested list. One way you could do that looks like

donor = [
    'George',
    'Soros',
    [                              #<- 2nd element of outermost list
        '99 First Street',
        [                          #<- 1st element of middling list
          '33 Broadway Avenue',
          'Apt 303',               #<- 1st element of innermost list
        ],
        '1 Park Avenue'
    ],
    'New York', 'NY',
]
Then, to extract "Apt 303", you could do
donor[2][1][1]

A better explaination of nested lists can be found if you ctrl-f search
for "nested list" on this chapter
<http://www.greenteapress.com/thinkpython/thinkCSpy/html/chap08.html> of
the book How to Think Like a Computer Scientist with python.

On Wed, Feb 24, 2016 at 2:59 PM, <grsm...@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']
>
> 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
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to