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


Groups > comp.lang.python > #106234

Re: Strange range

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: Strange range
Date Sat, 2 Apr 2016 01:45:00 +1100
Lines 33
Message-ID <mailman.314.1459521903.28225.python-list@python.org> (permalink)
References <87y48xjwqq.fsf@elektro.pacujo.net> <56fe76f2$0$22141$c3e8da3$5496439d@news.astraweb.com> <ndlvrt$1hlp$1@gioia.aioe.org> <mailman.311.1459521083.28225.python-list@python.org> <87lh4xjt37.fsf@elektro.pacujo.net>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de wuLtxCHcUv7JasRYWeQ35AmV6ubHRwBpJJHA9zsTASEQ==
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'cc:addr:python-list': 0.09; 'itself.': 0.11; 'index': 0.13; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterators': 0.16; 'no;': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'odd': 0.18; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; 'sat,': 0.23; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'chris': 0.26; 'message-id:@mail.gmail.com': 0.27; "can't": 0.32; 'except': 0.34; 'received:google.com': 0.35; 'false': 0.35; 'level': 0.35; 'received:209.85': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'seem': 0.37; 'received:209': 0.38; 'test': 0.39; 'within': 0.64; 'chrisa': 0.84; 'destructive': 0.84; 'to:none': 0.91
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:cc; bh=S9MRBMW44POK8H1ai6h1cO8za4zrIPdpIdb29x1S/3o=; b=QoS4LP4SZcOL/tJtXKyWi4rMsB6E5T+msImkFPDDKI/j5igTOqrTJ8HgaSrFbGXKh0 CGwWByunpEL7ksgE2oOAaaEq14oypGh1IlpUlLJ8SAR4EH87SLVH0bIRTGNULd44M5Ej zwGiSYz+/V28BlOdASJXSYZGajTc7OcVWgKa37G5EdqlSQ+UmWB/xtaYXKOMaPevugWe JIzHuCE1b3L6eEBrB3/ZrR99gEsFV71087mC6W+0Tw5ZajHrcoFBTgYmwOmuQtv04cBQ 9z5MpeR+mkHCcMMjEN52VjigxDKVrWnJfcsjoxVT1IteCYiRy7t0CRrBflXN2px888/X C1yg==
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:date :message-id:subject:from:cc; bh=S9MRBMW44POK8H1ai6h1cO8za4zrIPdpIdb29x1S/3o=; b=LVaBm3L8Js+t+1j6firA67QvdTr9XMrfWKHpknOecnQ58t+Meow/Sf3NenFT81We5X QfLr7WF6LXcqR9dyxaQrBauTjlOy82aKVadrJ5dWR9YqhuTUU9TYOWfMXditrukPEB1L 0KrQYZPchW56hosTG9l6Xh/rbDXVFRSblAOeZ93E3lUHSeeLm+gHKsdGoR7E5ZvIuJbP NwpDNFU4F/cEzamOOWxe4CwbrymYmwRTqVH3cY0NgwamLILczoX+SUhgp3OnqjGSVY2K SjFJ5fICcdF6/1gegpL5hb8JwaCC7WoMCaA2hJsx2BlZP4RvwGz5sNDhC4NDjbXuTKWn qo0g==
X-Gm-Message-State AD7BkJJu5r7+vPb3JT4Vb/TAoQXJngPknHLwwmm5NMdD2mA/ckPJULNTpWcqak6OZTfuQJZOP1zcP9UGRputEQ==
X-Received by 10.51.17.34 with SMTP id gb2mr3928414igd.13.1459521900972; Fri, 01 Apr 2016 07:45:00 -0700 (PDT)
In-Reply-To <87lh4xjt37.fsf@elektro.pacujo.net>
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:106234

Show key headers only | View raw


On Sat, Apr 2, 2016 at 1:34 AM, Marko Rauhamaa <marko@pacujo.net> wrote:
> Chris Angelico <rosuav@gmail.com>:
>
>> *A range object is not an iterator.*
>
> We now have learned as much.
>
> However, doesn't that extra level of indirection seem like an odd
> choice?

No; a range object is an entity in itself. You can test if something's
within the range:

>>> 5 in range(2,10)
True
>>> 5 in range(2,10,2)
False

You can ask how many numbers are in the range:

>>> len(range(2,10,2))
4

You can even ask what position a number would be in, if you index
through the range:

>>> range(3,100,3).index(57)
18

Iterators can't do any of this, except the 'in' check, which is
destructive and O(N).

ChrisA

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


Thread

Strange range Marko Rauhamaa <marko@pacujo.net> - 2016-04-01 16:15 +0300
  Re: Strange range Chris Angelico <rosuav@gmail.com> - 2016-04-02 00:24 +1100
  Re: Strange range Steven D'Aprano <steve@pearwood.info> - 2016-04-02 00:26 +1100
    Re: Strange range Marko Rauhamaa <marko@pacujo.net> - 2016-04-01 17:12 +0300
      Re: Strange range Random832 <random832@fastmail.com> - 2016-04-01 10:39 -0400
    Re: Strange range Fabien <fabien.maussion@gmail.com> - 2016-04-01 16:16 +0200
      Re: Strange range Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-01 17:28 +0300
      Re: Strange range Chris Angelico <rosuav@gmail.com> - 2016-04-02 01:31 +1100
        Re: Strange range Marko Rauhamaa <marko@pacujo.net> - 2016-04-01 17:34 +0300
          Re: Strange range Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-04-01 17:44 +0300
          Re: Strange range Chris Angelico <rosuav@gmail.com> - 2016-04-02 01:45 +1100
            Re: Strange range Marko Rauhamaa <marko@pacujo.net> - 2016-04-01 18:43 +0300
          Re: Strange range Erik <python@lucidity.plus.com> - 2016-04-01 20:58 +0100
            Re: Strange range Marko Rauhamaa <marko@pacujo.net> - 2016-04-01 23:14 +0300
              Re: Strange range Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-04-01 20:21 +0000
                Re: Strange range Marko Rauhamaa <marko@pacujo.net> - 2016-04-01 23:44 +0300
              Re: Strange range Steven D'Aprano <steve@pearwood.info> - 2016-04-02 21:09 +1100
                Re: Strange range Marko Rauhamaa <marko@pacujo.net> - 2016-04-02 13:48 +0300
          Re: Strange range Ned Batchelder <ned@nedbatchelder.com> - 2016-04-02 12:47 -0700
            Re: Strange range Marko Rauhamaa <marko@pacujo.net> - 2016-04-02 23:44 +0300
              Re: Strange range Chris Angelico <rosuav@gmail.com> - 2016-04-03 07:05 +1000
                Re: Strange range Marko Rauhamaa <marko@pacujo.net> - 2016-04-03 00:40 +0300
                Re: Strange range Ned Batchelder <ned@nedbatchelder.com> - 2016-04-02 14:50 -0700
                Re: Strange range Stephen Hansen <me+python@ixokai.io> - 2016-04-02 23:43 -0700
                Re: Strange range Marko Rauhamaa <marko@pacujo.net> - 2016-04-03 09:58 +0300
                Re: Strange range Chris Angelico <rosuav@gmail.com> - 2016-04-03 17:10 +1000
                Re: Strange range Ethan Furman <ethan@stoneleaf.us> - 2016-04-03 09:28 -0700
                Re: Strange range Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-04-04 13:21 +0100
                Re: Strange range Chris Angelico <rosuav@gmail.com> - 2016-04-03 17:08 +1000
              Re: Strange range Steven D'Aprano <steve@pearwood.info> - 2016-04-03 14:43 +1000
                Re: Strange range Random832 <random832@fastmail.com> - 2016-04-03 01:20 -0400
                Re: Strange range Steven D'Aprano <steve@pearwood.info> - 2016-04-03 15:28 +1000
      Re: Strange range Marko Rauhamaa <marko@pacujo.net> - 2016-04-01 17:32 +0300
  Re: Strange range Random832 <random832@fastmail.com> - 2016-04-01 10:42 -0400
  Re: Strange range Chris Angelico <rosuav@gmail.com> - 2016-04-02 01:50 +1100
  Re: Strange range Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-01 08:52 -0600

csiph-web