[Python-ideas] More useful slices

Chris Angelico rosuav at gmail.com
Mon Feb 2 11:53:59 CET 2015


On Mon, Feb 2, 2015 at 9:26 PM, Todd <toddrjen at gmail.com> wrote:
> 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.

Considering the single most common use of ranges, let's see how a for
loop would look:

for i in 1:10:
    pass

Is that nastily cryptic, or beautifully clean? I'm inclined toward the
former, but could be persuaded.

ChrisA


More information about the Python-ideas mailing list