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: 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: References: Date: Fri, 3 Jan 2014 19:15:26 -0500 Subject: Re: Creating a list with holes From: Larry Martell To: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Fri, Jan 3, 2014 at 1:07 PM, Denis McMahon 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.