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


Groups > comp.lang.python > #63092

Re: Creating a list with holes

References <CACwCsY5P47-dB1NLQTUTQ=0aF6B+-M3y4hCxcUGmcVmHM8=-xQ@mail.gmail.com> <CAPTjJmp+NtGYWE3S3SGjo-xoYC74Exdpci_+x4AUNgqM5=CJNQ@mail.gmail.com> <CACwCsY6J0-v0EfKRj5XCCdL9ym6MxpGuXqu93DXLuhVOhuRVJw@mail.gmail.com> <CAPTjJmphBdTObUKQyk9nwSjN60zqUnHScYZ0OJA6Oym+2cDe_Q@mail.gmail.com>
Date 2014-01-03 19:18 -0500
Subject Re: Creating a list with holes
From Larry Martell <larry.martell@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.4872.1388794708.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, Jan 3, 2014 at 11:07 AM, Chris Angelico <rosuav@gmail.com> wrote:
> On Sat, Jan 4, 2014 at 2:55 AM, Larry Martell <larry.martell@gmail.com> wrote:
>> The use case is that I'm parsing a XML file like this:
>>
>>           <Parameter Name="DefaultVersion">
>>             <Values>
>>               <Value>
>>                 <Default>True</Default>
>>               </Value>
>>             </Values>
>>             <Values>
>>               <Value>
>>                 <Current>False</Current>
>>               </Value>
>>             </Values>
>>             <Values>
>>               <Value>
>>                 <Default>True</Default>
>>                 <Current>False</Current>
>>               </Value>
>>             </Values>
>>             <Values>
>>               <Default>True</Default>
>>             </Values>
>>
>> This is an existing program that is putting the data into a dict. The
>> dict keys are ['DefaultVersion','Default'] and
>> ['DefaultVersion','Current']. These contain lists that have the
>> True/False values.
>
> Are you assigning keys by value, or are you simply appending to the
> lists? It looks to me like you could simply append another element to
> both lists for each <Value> </Value> unit, with the given Default and
> Current if available, or with None for any that aren't set.
> Alternatively, when you get up to the <Value>, append None to each
> list, and then when you see a value, assign to [-1] and overwrite the
> None.

Your last suggestion is what I ended up doing, but I had to key off
the <Values> </Values> unit - I couldn't use <Value> because that
isn't present for ones that have no <Current> - that messed me up for
hours. But it's working now. Thanks all!

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


Thread

Re: Creating a list with holes Larry Martell <larry.martell@gmail.com> - 2014-01-03 19:18 -0500

csiph-web