[Python-ideas] More useful slices

David Mertz mertz at gnosis.cx
Mon Feb 2 13:57:24 CET 2015


> It would be
>
> for i in (1:10):
>    pass

If you can spare one character you can define a function similar to take
that takes a slice object as agreement. Then call it like:

for i in I(1:10):
    # do stuff

No change in syntax needed, probably 6 lines in the function definition.

I chose 'I' for Integers, and because it looks small. You could use a
different one letter name.


> Anyone who uses sequences should be familiar with this sort of notation:
>
> for i in spam[1:10]:
>   pass
>
> So should have at least some understanding that 1:10 can mean "1 to 10,
not including 10".
>
> I don't see it being any more cryptic than {'a': 1, 'b': 2} meaning
dict(a=1, b=2).  On the contrary, I think the dict literal syntax is even
more cryptic, since it has no similarity to any other syntax.  The syntax I
propose here is at least similar (although not identical) to slicing.
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150202/b689ba25/attachment-0001.html>


More information about the Python-ideas mailing list