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


Groups > comp.lang.python > #103466

Re: Nested List question

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From <grsmith@atlanticbb.net>
Newsgroups comp.lang.python
Subject Re: Nested List question
Date Wed, 24 Feb 2016 17:33:20 -0500
Lines 74
Message-ID <mailman.109.1456353212.20994.python-list@python.org> (permalink)
References <4AD2810BE3B346399F777EDEAB079BDA@OPTIPLEX990> <56CE2098.2070507@lucidity.plus.com>
Mime-Version 1.0
Content-Type text/plain; format=flowed; charset="Windows-1252"; reply-type=response
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de Q8qDjo0HRJsxawVkENII+Q9PhDq/W58TbmjoPTCBY27g==
Return-Path <grsmith@atlanticbb.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.061
X-Spam-Evidence '*H*': 0.88; '*S*': 0.00; 'else:': 0.03; 'wednesday,': 0.07; 'subject:question': 0.08; 'str):': 0.09; 'message-----': 0.15; '2016': 0.16; '24,': 0.16; '303': 0.16; 'erik': 0.16; 'guessing': 0.16; 'mark,': 0.16; 'nest': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'structure.': 0.16; 'wrote:': 0.16; 'nested': 0.18; 'to:2**1': 0.21; 'bit': 0.23; 'tried': 0.24; 'words': 0.24; 'header:In-Reply-To:1': 0.24; 'figure': 0.27; 'question': 0.27; 'that.': 0.30; 'to:name:python- list': 0.30; 'received:10.0.0': 0.32; 'addresses,': 0.33; 'subject:List': 0.33; 'skip:- 10': 0.34; 'correctly': 0.34; 'structure': 0.34; 'received:10.0': 0.34; 'list': 0.34; 'sent:': 0.35; 'could': 0.35; 'park': 0.35; 'something': 0.35; 'subject:': 0.35; 'expected': 0.35; 'but': 0.36; 'list,': 0.36; 'should': 0.36; "wasn't": 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'thanks': 0.37; 'list.': 0.37; 'several': 0.38; 'mean': 0.38; 'why': 0.39; 'goes': 0.39; 'data': 0.39; 'from:': 0.39; 'to:addr:python.org': 0.40; 'from:no real name:2**0': 0.60; 'your': 0.60; 'address': 0.61; 'charset:windows-1252': 0.62; 'above,': 0.63; 'more': 0.63; 'you.': 0.64; 'python-list': 0.66; 'apart': 0.70; 'presented': 0.72; 'address,': 0.77; 'received:38': 0.81; 'addresses:': 0.84; 'avenue.': 0.84; 'received:38.111': 0.84; 'surname,': 0.84; 'broadway': 0.91; 'tied': 0.93
X-Scanner-Info Cloudmark - http://www.cloudmark.com
X-CNFS-Analysis v=2.1 cv=U+Zvdrfu c=1 sm=1 tr=0 a=wmZXJE1MrsZYcnKSeUNejA==:117 a=wmZXJE1MrsZYcnKSeUNejA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=N659UExz7-8A:10 a=43beU8AwAAAA:8 a=v7CqaaOlB21UdseeLJAA:9 a=8ix3We0KtVrtHFCl:21 a=WMAnm43bzIgbgw0i:21 a=pILNOxqGKmIA:10
X-CMAE-Score 0.00
X-Scanned-by CMAE
X-AUTH-ID grsmith@atlanticbb.net
In-Reply-To <56CE2098.2070507@lucidity.plus.com>
X-Priority 3
X-MSMail-Priority Normal
Importance Normal
X-Mailer Microsoft Windows Live Mail 15.4.3555.308
X-MimeOLE Produced By Microsoft MimeOLE V15.4.3555.308
X-CMAE-Envelope MS4wfFdp1dR2SFEOMjVNBCTRuYlsQAVBxW0nBjngUpJCTvsnIANor+RrxqSpXk0wLPe6ezHMYo0PB24JTg0FKwyFHs7owYNYKgmy/BV2zUhLpyUhXRXhPbeZyo9tn6dDiqNK8GcGDhfZzprFrhJ5FNInyhzXeUmwx900WBeVgg61CQSBNkmyHYtjIn+Kh/ss0dGeh2W0zZtrL3pK1Jwm/ryoAaE8G7ioNc/wlFzz6MQAP3/XVCInvlXgMp8V3P7C5uFVQA==
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21rc2
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:103466

Show key headers only | View raw


Erik,

Works perfectly, thanks much !!!
Mark, I am tied to data structure.

for address in addresses:
    if isinstance(address, str):
        apt = None
        print(address, apt)
    else:
        address, apt = address
        print(address, apt)


99 First Street None
33 Broadway Avenue Apt 303
1 Park Avenue None


-----Original Message----- 
From: Erik
Sent: Wednesday, February 24, 2016 4:28 PM
To: grsmith@atlanticbb.net ; python-list
Subject: Re: Nested List question

On 24/02/16 20:59, grsmith@atlanticbb.net wrote:
> 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.

The way to keep those particular items together is to have something like:

data = \
['George', 'Soros',
   [ '99 First Street',
     ['33 Broadway Avenue', 'Apt 303'],
     '1 Park Avenue'
   ],
   'New York', 'NY'
]

And then, guessing from the structure of your list, you'd do something like:

forename, surname, addresses, city, state = data

And then, something like:

for address in addresses:
   if type(address) == StringType:
     apt = None
   else:
     address, apt = address

That should work to pick apart with what you have presented above, but I
think you'd be better off presenting the data with a bit more structure
in the first place.

> 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 would be much easier to work out what you mean by this if you'd have
actually said what you'd tried and what you had expected to happen and
why what did happen wasn't right for you.

E. 

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


Thread

Re: Nested List question <grsmith@atlanticbb.net> - 2016-02-24 17:33 -0500

csiph-web