[Python-ideas] More useful slices

Todd toddrjen at gmail.com
Mon Feb 2 11:26:02 CET 2015


On Mon, Feb 2, 2015 at 11:03 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:

>
> On 2 Feb 2015 01:14, "Todd" <toddrjen at gmail.com> wrote:
> >
> > Although slices and ranges are used for different things and implemented
> differently, conceptually they are similar: they define an integer sequence
> with a start, stop, and step size.  For this reason I think that slices
> could provide useful syntactic sugar for defining ranges without
> sacrificing clarity.
>
> Why is this beneficial? We'd be replacing an easily looked up builtin name
> with relatively cryptic syntax.
>
>

First, it wouldn't be a replacement.  The existing range syntax would still
exist.

But the reason it is beneficial is the same reason we have [a, b, c] for
list, {a:1, b:2, c:3} for dicts, {a, b, c} for sets, and (a, b, c) for
tuples.  It is more compact way to create a commonly-used data structure.

And I wouldn't consider it any more cryptic than any other literal we
have.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150202/6ab71733/attachment-0001.html>


More information about the Python-ideas mailing list