Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'guido': 0.05; 'advocate': 0.07; 'indices': 0.07; 'rejected': 0.07; 'python': 0.09; 'counting': 0.09; 'expectation': 0.09; 'integers': 0.09; 'loop.': 0.09; 'patch.': 0.09; 'semantics': 0.09; 'slices': 0.09; '24,': 0.16; 'below;': 0.16; 'idea:': 0.16; 'inclusive.': 0.16; 'loops': 0.16; 'range,': 0.16; 'range.': 0.16; 'ranges.': 0.16; 'subject:)?': 0.16; 'syntax,': 0.16; 'url:patches': 0.16; 'value;': 0.16; 'wrote:': 0.17; 'feb': 0.19; 'tracker': 0.20; 'all,': 0.21; 'converted': 0.22; 'explicit': 0.22; 'this:': 0.23; "i've": 0.23; 'patch': 0.24; 'raise': 0.24; 'second': 0.24; 'url:bugs': 0.24; 'header:In-Reply-To:1': 0.25; '(which': 0.26; 'values': 0.26; 'andrew': 0.27; 'instead.': 0.27; 'message- id:@mail.gmail.com': 0.27; 'actual': 0.28; 'run': 0.28; 'accidentally': 0.29; 'idea,': 0.29; 'implicitly': 0.29; 'loop,': 0.29; 'prints': 0.29; 'no,': 0.29; 'error': 0.30; 'url:python': 0.32; 'not.': 0.32; 'print': 0.32; 'problem': 0.33; 'to:addr :python-list': 0.33; 'code:': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'same.': 0.35; 'sequence': 0.35; 'pm,': 0.35; 'received:209.85.220': 0.35; 'continue': 0.35; 'received:209.85': 0.35; 'next': 0.35; 'really': 0.36; 'but': 0.36; 'url:org': 0.36; 'should': 0.36; 'subject: (': 0.36; 'one,': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'think': 0.40; 'easy': 0.60; 'range': 0.60; "you've": 0.61; 'first': 0.61; 'between': 0.63; 'different': 0.63; 'reasons,': 0.65; 'ranges': 0.71; '2013': 0.84; 'to:name:python': 0.84; 'url:ml': 0.84; 'hand,': 0.97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=zTrW1nQKYH2VjzVioZMmooGO3D1ynWNBuw3U4nCQ+5g=; b=QD8iiy/m7GxaPpQpCriHcp41iDMaeCNbn6hAe5lePjgmP5Y+k+4Y1XdBn5mAceKEmD 5GTU/ovG4Gy8cZ6ccPwTnG8hdQXuOlj7LP2w+NcAU+SYFX+gH2qbwnraUsWpge1Hee4V d4CXi12tIhBprhAfTU7FMKf0sKFeXhWCwI88x6ya9CQ6eGFg8WmqeRddsrWMqEVFgxkz Fr1fS2kY47wBmvl5fnzrMdTEDNOtXpVi0BpncSyJMN4JYLfwAlmAB0HW+r8xsxqo5W4s EQA8raNW8wDzAjeEw7MEh0/Ad8AxUl9yP/pkQ/sj07nopIt+4EXZoXPP+uyUmWbaIUlD BKZg== X-Received: by 10.220.156.8 with SMTP id u8mr9584018vcw.24.1361788127454; Mon, 25 Feb 2013 02:28:47 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <512ABA02.2080709@r3dsolutions.com> References: <2e07acfb-4f48-4a27-9b06-3d8103325c0f@googlegroups.com> <512ABA02.2080709@r3dsolutions.com> From: Ian Kelly Date: Mon, 25 Feb 2013 03:28:06 -0700 Subject: Re: Suggested feature: slice syntax within tuples (or even more generally)? To: Python Content-Type: text/plain; charset=ISO-8859-1 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: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361788135 news.xs4all.nl 6929 [2001:888:2000:d::a6]:34326 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39884 On Sun, Feb 24, 2013 at 6:10 PM, Andrew Robinson wrote: > I've read through the whole of the subject, and the answer is no, although I > think allowing it in (::) is a *very* good idea, including as a replacement > for range or xrange. > > s=1:2:3 > for i in s: > for i in (1:2:3) : Eww, no. I can appreciate the appeal of this syntax, but the problem is that ranges and slices are only superficially similar. For one, ranges require a stop value; slices do not. What should Python do with this: for i in (:): Intuitively, it should result in an infinite loop starting at 0. But ranges require a stop value for a very good reason -- it should not be this easy to accidentally create an infinite for loop. So I would advocate that this should raise an error instead. If the user really wants an unlimited counting loop, let them continue to be explicit about it by using itertools.count. On the other hand, this would mean that the semantics of (:) would be different depending on whether the slice is used as a slice or a range. The next problem you run into is that the semantics of negative numbers are completely different between slices and ranges. Consider this code: s = (-5:6) for i in s: print(i) for i in range(6)[s]: print(i) Intuitively, both loops should print the same thing. After all, one is using the slice s as a range, and the other is using the very same slice s as a slice of a sequence where the indices and values are the same. This expectation fails, however. The first loop prints the integers from -5 to 5 inclusive, and the second loop only prints the integers from 1 to 5 inclusive. For these reasons, I disagree that allowing slices to be implicitly converted to ranges or vice versa is a good idea. > This is not a new idea: eg: 2002. (which is still status OPEN). > http://osdir.com/ml/python.patches/2002-06/msg00319.html It's not still open. What you've linked above is an archived mailing list message concerning the patch. I've linked the actual tracker issue that the patch was attached below; it was rejected by Guido in 2002. http://bugs.python.org/issue575515