Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63069
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <larry.martell@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'skip:[ 20': 0.04; 'assign': 0.07; 'element': 0.07; 'list?': 0.07; 'iterate': 0.09; 'parsing': 0.09; 'rewrite': 0.09; 'yeah,': 0.09; 'jan': 0.12; "wouldn't": 0.14; 'be:': 0.16; 'defaultdict': 0.16; 'dict': 0.16; 'different,': 0.16; 'elements,': 0.16; 'googled': 0.16; 'singleton': 0.16; 'skip:[ 30': 0.16; 'subclass': 0.16; 'write.': 0.16; 'sat,': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'not,': 0.20; 'code,': 0.22; 'putting': 0.22; 'to:name:python-list@python.org': 0.22; 'creating': 0.23; 'exists': 0.24; 'options': 0.25; 'handling': 0.26; 'order.': 0.26; 'this:': 0.26; 'header:In-Reply- To:1': 0.27; 'function': 0.29; 'correct': 0.29; 'chris': 0.29; 'am,': 0.29; 'xml': 0.29; 'subject:list': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'keys': 0.31; 'larry': 0.31; 'values.': 0.31; 'allows': 0.31; 'file': 0.32; 'lists': 0.32; 'probably': 0.32; 'run': 0.32; 'fri,': 0.33; 'maybe': 0.34; "i'd": 0.34; 'subject:with': 0.35; 'something': 0.35; 'no,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'false': 0.36; 'processed': 0.36; "didn't": 0.36; 'possible': 0.36; 'should': 0.36; 'list': 0.37; 'e.g.': 0.38; 'ends': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'expect': 0.39; 'morning': 0.39; 'to:addr:python.org': 0.39; 'space': 0.40; 'most': 0.60; 'myself': 0.63; 'decided': 0.64; 'worth': 0.66; 'night,': 0.68; 'filling': 0.78; 'case?': 0.84; 'dict.': 0.84; 'different.': 0.84; 'holes': 0.84; "it'd": 0.84; 'slots.': 0.84; 'yours': 0.88 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=66odPI0aV+xv/XGbTPa2zFbCW/MBkB8je2qLnziGB34=; b=iVx9oMUJS1191RU3YZbDjP031upzNBSbnzlyAqQpaP8Ry1B32pCKidZRWDmNIrjiem 6AJfdx16tDjJhzUMm6jwgP7TW73g4LI0Xej4uVTBiXT2sb3oWLNbd0IX4ZcH4gAHtfIl p6JzDQFEXSx35Mz79vOFzFvWG90KQOMK6yALoAAxdS8JkyC3w+AR7/gaUM7QAXunWBkW YrJrxjfT+nkj/ipnXx63AFouZWonWYQHYz9U8fnQLonOSsGn5g5pOsWKcjLmzA4FUFLA RdnMwbfdBwzOenHsuGEvhP+pZVHgH4h+f0MVoG5fwQzzWY8H2ecVml0RVEcsnRzZKQmj uNUg== |
| MIME-Version | 1.0 |
| X-Received | by 10.194.57.19 with SMTP id e19mr284293wjq.93.1388764558323; Fri, 03 Jan 2014 07:55:58 -0800 (PST) |
| In-Reply-To | <CAPTjJmp+NtGYWE3S3SGjo-xoYC74Exdpci_+x4AUNgqM5=CJNQ@mail.gmail.com> |
| References | <CACwCsY5P47-dB1NLQTUTQ=0aF6B+-M3y4hCxcUGmcVmHM8=-xQ@mail.gmail.com> <CAPTjJmp+NtGYWE3S3SGjo-xoYC74Exdpci_+x4AUNgqM5=CJNQ@mail.gmail.com> |
| Date | Fri, 3 Jan 2014 10:55:58 -0500 |
| Subject | Re: Creating a list with holes |
| From | Larry Martell <larry.martell@gmail.com> |
| To | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4858.1388764566.18130.python-list@python.org> (permalink) |
| Lines | 73 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1388764566 news.xs4all.nl 2919 [2001:888:2000:d::a6]:48200 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:63069 |
Show key headers only | View raw
On Fri, Jan 3, 2014 at 10:37 AM, Chris Angelico <rosuav@gmail.com> wrote:
> On Sat, Jan 4, 2014 at 2:19 AM, Larry Martell <larry.martell@gmail.com> wrote:
>> I think I know the answer is no, but is there any package that allows
>> creating a list with holes in it? E.g. I'd want to do something like:
>>
>> x[10] = 12
>> x[20] = 30
>>
>> I'm thinking of something like defaultdict but for lists (I know
>> that's very different, but ... )
>
> Depending on what exactly you need, it's probably worth just using a
> dict. In what ways do you need it to function as a list? You can
> always iterate over sorted(some_dict.keys()) if you need to run
> through them in order.
>
> Alternatively, if you expect to fill in most of the elements, it's
> possible you'd be happier working with a subclass of list that
> auto-expands by filling in the spare space with a singleton meaning
> "no element here". The code probably exists somewhere, but if not, it
> wouldn't be hard to write. Then it'd be a list, but you can start with
> it empty and assign as you describe above.
>
> What's the use case? I expect that one or the other of those options
> would cover most cases, but maybe yours is different.
Yeah, googled and didn't find anything, then started writing it myself
last night, then this morning decided to ask if it already existed.
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. It's currently not correctly handling the missing
items so it ends up with:
['DefaultVersion','Default'][0] = True
['DefaultVersion','Default'][1] = True
['DefaultVersion','Current'][0] = False
When it should be:
['DefaultVersion','Default'][0] = True
['DefaultVersion','Default'][1] = None
['DefaultVersion','Current'][0] = None
And so on.
This dict/list is then processed by other existing code, so I don't
want to have to rewrite a ton of code - I just want to fix the list so
the items end up in their correct slots.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Creating a list with holes Larry Martell <larry.martell@gmail.com> - 2014-01-03 10:55 -0500
csiph-web