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


Groups > comp.lang.python > #63090

Re: Creating a list with holes

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!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.089
X-Spam-Evidence '*H*': 0.82; '*S*': 0.00; 'jan': 0.12; '[10]': 0.16; 'here"': 0.16; 'none.': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'code.': 0.18; 'value.': 0.19; 'example': 0.22; 'to:name:python- list@python.org': 0.22; '(or': 0.24; 'pass': 0.26; 'header:In- Reply-To:1': 0.27; 'subject:list': 0.30; 'message- id:@mail.gmail.com': 0.30; '>>>>': 0.31; 'larry': 0.31; 'fri,': 0.33; 'skip:d 20': 0.34; 'subject:with': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'in.': 0.36; 'returning': 0.36; 'method': 0.36; 'list': 0.37; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'above,': 0.60; 'god': 0.65; 'between': 0.67; 'default': 0.69; 'dic': 0.84; 'holes': 0.84
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=rsrMM+sq0+Pv+VrTCtU4Iwrt9m/9esoHdPIDT2LFms0=; b=VEvX6xIQTFQr/AkU5S73NkjGKXZ0eGaLUhLQ3Xpi4ZZJLRCwX+In+KEgrw2ABdhvDy wau95unF3v/dQCq7mFtLbvE7gV6IUjicJ8+hClL6Ypa1OT+/fsdmpvDTAFz+BMb7E+gq eC9WW5Wfd7tmttRlCpaYoGrVlq3U6rE5IhnrAhaMYYule085DTOBPD6txxI/V1AIkqZE 6WBc0qpgiz3TAYsaVDe+2gtaVWpwL4i44/aMqLQwJ+Hwfd/Yti/itDFkDscM+1DqaGr6 Qihi5PoLzw3D4VxRP+duzE8eXzxNGeIfLKi1o5kohVC+fU2RAp6vjH6bahrsobKy8zlh 81Sg==
MIME-Version 1.0
X-Received by 10.194.62.8 with SMTP id u8mr1785163wjr.68.1388794526117; Fri, 03 Jan 2014 16:15:26 -0800 (PST)
In-Reply-To <la6u8e$lf9$3@dont-email.me>
References <mailman.4852.1388762356.18130.python-list@python.org> <c37ad1f1-1367-4de0-9a2e-bc60355abea3@googlegroups.com> <mailman.4856.1388763689.18130.python-list@python.org> <la6u8e$lf9$3@dont-email.me>
Date Fri, 3 Jan 2014 19:15:26 -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.4871.1388794533.18130.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1388794533 news.xs4all.nl 2938 [2001:888:2000:d::a6]:58661
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:63090

Show key headers only | View raw


On Fri, Jan 3, 2014 at 1:07 PM, Denis McMahon <denismfmcmahon@gmail.com> wrote:
> On Fri, 03 Jan 2014 10:41:21 -0500, Larry Martell wrote:
>
>> The holes would be between the items I put in. In my example above, if I
>> assigned to [10] and [20], then the other items ([0..9] and [11..19])
>> would have None.
>
>>>> dic = { 10:6, 20:11}
>>>> dic.get(10)
> 6
>>>> dic.get(14)
>>>> dic.get(27,"oh god there's nothing here")
> "oh god there's nothing here"
>>>> dic.get(99,None)
>>>> dic.get(168,False)
> False
>>>> dic.get(20,"Boo Yah")
> 11
>>>>
>
> So a standard dictionary does this returning None (or any other default
> value you care to pass it) as long as you use the dict.get(key[,default])
> method rather than dict[key] to return the value.
>
> See also:
>
> http://stackoverflow.com/questions/6130768/return-none-if-dictionary-key-
> is-not-available

Thanks, but I know all that about dicts. I need to use a list for
compatibility with existing code.

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


Thread

Creating a list with holes Larry Martell <larry.martell@gmail.com> - 2014-01-03 10:19 -0500
  Re: Creating a list with holes eneskristo@gmail.com - 2014-01-03 07:30 -0800
    Re: Creating a list with holes Larry Martell <larry.martell@gmail.com> - 2014-01-03 10:41 -0500
      Re: Creating a list with holes Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-03 18:07 +0000
        Re: Creating a list with holes Larry Martell <larry.martell@gmail.com> - 2014-01-03 19:15 -0500
          Re: Creating a list with holes Roy Smith <roy@panix.com> - 2014-01-03 20:18 -0500
            Re: Creating a list with holes Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-04 02:03 +0000
  Re: Creating a list with holes Roy Smith <roy@panix.com> - 2014-01-03 10:38 -0500
    Re: Creating a list with holes Chris Angelico <rosuav@gmail.com> - 2014-01-04 02:46 +1100

csiph-web