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


Groups > comp.lang.python > #106170

Re: Slice equivalent to dict.get

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: Slice equivalent to dict.get
Date Thu, 31 Mar 2016 09:43:50 -0600
Lines 14
Message-ID <mailman.267.1459439072.28225.python-list@python.org> (permalink)
References <56fd3d17$0$1606$c3e8da3$5496439d@news.astraweb.com> <ndjfg3$b3k$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de ZE+LBZfGEbbRHNHSxoJh1wHob6M3zSYOYKBv9S8UHL8A==
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.027
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'indexing': 0.07; "'default'": 0.09; '-1,': 0.09; 'indexes': 0.09; 'def': 0.13; 'explicitly': 0.15; 'thu,': 0.15; '2016': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'first,': 0.20; '31,': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'message- id:@mail.gmail.com': 0.27; 'idea': 0.28; 'index,': 0.29; 'skip:[ 10': 0.31; "can't": 0.32; 'received:google.com': 0.35; 'trouble': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'seem': 0.37; 'things': 0.38; 'received:209': 0.38; 'end': 0.39; 'to:addr:python.org': 0.40; 'more': 0.63; 'between': 0.65; 'mar': 0.65; 'note:': 0.66; 'otten': 0.84; 'pain': 0.84; 'to:name:python': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=vv2uWuc6AXSyyICbs7OzMZvFFXMLpOZTO8OF+I43wMw=; b=H0ANqAo8NQIe698/AfIbo8QnHmxsoMOC1vc/bLfYbT/qCAZ2pjzG6pucZaVVcvYQUN WFa+FAh9Zm4slPX6bM0edFcHs4r2Ef5nc0l+xtwvUUIrtKoKglHZghfrN72wg1IzTena w5h6qVhCfCDTchDMKrblBIQwyqk7eBkdFdz0CEBZcl0gzgfWO7lrEPQ/5M4Y/DuHwvX5 spX8LOF8OIenWMyLMVOG0NfRfWIbtPdwML7oqAaGYfPXYGYwVrJqYDZpAa7sxqIA4dFe TbuVoA2JRkEoK2FE20aGSRwTOFnXWlTQ7UzOoBSPP34yFLAqyZoXtsTNzL+/3aliqWGE i51g==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=vv2uWuc6AXSyyICbs7OzMZvFFXMLpOZTO8OF+I43wMw=; b=EViC7AIhhwKVayQ99IS1iDCT3ICXZMCuh2FAEG2zvUweEsjGYUHZ3cKwHkSrp9swVN wYAlJHHOmehlynisLmiDlPFvd1q2eu9gQ8qtUjHmxlIzXEcny6pFqazXmk/DlMbtHtOa N4AIAWBZs+DkGSHzxewHtxRZyfIJvNz0e422vvA+LusO2Oossfr6QNoK9CvskE7WiBHl +X/i0Or9Fl0r49uhOz4+8Pshsr/HZ7jT4B2HY/W/a+A7+hGESzWWJO9sDSO4lpbDw9QR t3oGRVeVoriCvqSZPVJ5upm95BiEk5zPlVe98pgoiBQtxHvPK4Sv1ekcHZ17TRlN1sWu Kixw==
X-Gm-Message-State AD7BkJLDsxHMrhKhDjdGoreKJTCnrU/f5+f7vH9UGRIJqxm0Sf5aVUwsfPxu4cTgN8v8z93eJz2kR51+0yBNPA==
X-Received by 10.50.131.201 with SMTP id oo9mr3576720igb.68.1459439070035; Thu, 31 Mar 2016 08:44:30 -0700 (PDT)
In-Reply-To <ndjfg3$b3k$1@ger.gmane.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
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:106170

Show key headers only | View raw


On Thu, Mar 31, 2016 at 9:24 AM, Peter Otten <__peter__@web.de> wrote:
> But note:
>
>>>> def get(seq, index, default=None):
> ...     return (seq[index:index+1] or [default])[0]
> ...
>>>> get("abc", -1, "default")
> 'default'

The discontinuity between -1 and 0 in indexing is a pain in the rear.
Negative indexes are one of those things that may seem like a good
idea at first, but I think in the end it causes more trouble than it's
worth. There's nothing you can do with L[-x] that you can't do more
explicitly with L[len(L) - x].

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


Thread

Slice equivalent to dict.get Steven D'Aprano <steve@pearwood.info> - 2016-04-01 02:07 +1100
  Re: Slice equivalent to dict.get Peter Otten <__peter__@web.de> - 2016-03-31 17:24 +0200
  Re: Slice equivalent to dict.get Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-31 09:43 -0600
  Re: Slice equivalent to dict.get "Sven R. Kunze" <srkunze@mail.de> - 2016-03-31 18:05 +0200
  Re: Slice equivalent to dict.get Terry Reedy <tjreedy@udel.edu> - 2016-03-31 13:51 -0400
  Re: Slice equivalent to dict.get Zachary Ware <zachary.ware+pylist@gmail.com> - 2016-03-31 14:28 -0500

csiph-web