Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39884
| 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 | <ian.g.kelly@gmail.com> |
| 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> <kfhsc2$ubq$1@ger.gmane.org> <512ABA02.2080709@r3dsolutions.com> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Mon, 25 Feb 2013 03:28:06 -0700 |
| Subject | Re: Suggested feature: slice syntax within tuples (or even more generally)? |
| To | Python <python-list@python.org> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2497.1361788135.2939.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
On Sun, Feb 24, 2013 at 6:10 PM, Andrew Robinson
<andrew3@r3dsolutions.com> 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Suggested feature: slice syntax within tuples (or even more generally)? stephenwlin@gmail.com - 2013-02-13 11:00 -0800
Re: Suggested feature: slice syntax within tuples (or even more generally)? Terry Reedy <tjreedy@udel.edu> - 2013-02-14 00:23 -0500
Re: Suggested feature: slice syntax within tuples (or even more generally)? stephenwlin@gmail.com - 2013-02-13 21:54 -0800
Re: Suggested feature: slice syntax within tuples (or even more generally)? stephenwlin@gmail.com - 2013-02-13 21:54 -0800
Re: Suggested feature: slice syntax within tuples (or even more generally)? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-14 07:32 +0000
Re: Suggested feature: slice syntax within tuples (or even more generally)? stephenwlin@gmail.com - 2013-02-14 00:36 -0800
Re: Suggested feature: slice syntax within tuples (or even more generally)? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-14 08:03 +0000
Re: Suggested feature: slice syntax within tuples (or even more generally)? stephenwlin@gmail.com - 2013-02-14 01:08 -0800
Re: Suggested feature: slice syntax within tuples (or even more generally)? stephenwlin@gmail.com - 2013-02-14 01:26 -0800
Re: Suggested feature: slice syntax within tuples (or even more generally)? Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-14 11:58 -0700
Re: Suggested feature: slice syntax within tuples (or even more generally)? stephenwlin@gmail.com - 2013-02-14 14:01 -0800
Re: Suggested feature: slice syntax within tuples (or even more generally)? stephenwlin@gmail.com - 2013-02-14 14:01 -0800
Re: Suggested feature: slice syntax within tuples (or even more generally)? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-14 17:46 -0800
Re: Suggested feature: slice syntax within tuples (or even more generally)? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-14 17:46 -0800
Re: Suggested feature: slice syntax within tuples (or even more generally)? stephenwlin@gmail.com - 2013-02-13 22:06 -0800
Re: Suggested feature: slice syntax within tuples (or even more generally)? Duncan Booth <duncan.booth@invalid.invalid> - 2013-02-14 12:25 +0000
Re: Suggested feature: slice syntax within tuples (or even more generally)? stephenwlin@gmail.com - 2013-02-14 07:56 -0800
Re: Suggested feature: slice syntax within tuples (or even more generally)? Andrew Robinson <andrew3@r3dsolutions.com> - 2013-02-25 01:10 +0000
Re: Suggested feature: slice syntax within tuples (or even more generally)? Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-25 03:28 -0700
Re: Suggested feature: slice syntax within tuples (or even more generally)? Terry Reedy <tjreedy@udel.edu> - 2013-02-25 06:23 -0500
Re: Suggested feature: slice syntax within tuples (or even more generally)? Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-25 09:54 -0700
Re: Suggested feature: slice syntax within tuples (or even more generally)? Andrew Robinson <andrew3@r3dsolutions.com> - 2013-02-25 09:47 +0000
Re: Suggested feature: slice syntax within tuples (or even more generally)? Nobody <nobody@nowhere.com> - 2013-02-26 07:38 +0000
csiph-web