Nested List question
amfarrell at mit.edu
Wed Feb 24 16:11:35 EST 2016
you can indeed have a nested list. One way you could do that looks like
donor = [
[ #<- 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
A better explaination of nested lists can be found if you ctrl-f search
for "nested list" on this chapter
the book How to Think Like a Computer Scientist with python.
On Wed, Feb 24, 2016 at 2:59 PM, <grsmith at atlanticbb.net> wrote:
> Can you have a phython list like:
> ['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.
More information about the Python-list