Contraction for "for x in range()"

I have a small syntax idea. In short, contraction of for x in range(a,b,c) : to for x in a,b,c : I really think there is something cute in it. So like a shortcut for range() which works only in for-in statement. So from syntactical POV, do you find it nice syntax? Visually it seems to me less bulky than range(). Example: for x in 0,5 : print (x) for y in 0,10,2 : print (y) for z in 0, y+8 : print (z) Which would be short for: for x in range(0,5): print (x) for y in range(0,10,2): print (y) for z in range(0, y+8): print (z) Mikhail

for i in range(...) is *sometimes* indicative of code smell, especially when then doing x[i], though it has its uses. I've never had a need to shorten a for...range line though. Other than it being "cute", do you have an example where it's definitively better? On Tue, Feb 14, 2017 at 4:03 PM, Todd <toddrjen@gmail.com> wrote:

Make some shim object that you can index into to get that functionality, could even call it Z (for the set of all integers). Short, and requires no new syntax. class IndexableRange: def __getitem__(self, item): if isinstance(item, slice): start = item.start if item.start is not None else 0 step = item.step if item.step is not None else 1 if item.stop is None: return itertools.count(start, step) else: return range(start, item.stop, step) else: return item Z = IndexableRange() for y in Z[0:10:2]: print(y) On Tue, Feb 14, 2017 at 5:22 PM, Mikhail V <mikhailwas@gmail.com> wrote:

On 15 February 2017 at 00:41, Nick Timkovich <prometheus235@gmail.com> wrote:
l can, also just make function r(a,b,c) : return range(a,b,c) for example, will look similar. Initially I was by the idea to remove brackets from for statement. Now after looking more at examples I realize what the real issue with the look is. Namely it is the word "in" itself. It is simply too short and that makes a lot of space holes in the lines. And letters 'i' and 'n' sort of suck from readability POV. E.g. compare: for x in 1,10,2: and for x over 1,10,2 : So the latter actually would make it look nicer. But that would probably be even less probable to be implemented. Mikhail

I would be surprised if this hasn't been suggested many times before. It's similar to Matlab's syntax: for x = start:step:finish <do whatever> end Any such change would represent a large departure from normal python syntax for dubious gain. In general, you can put any expression after the `in` keyword so long as it evaluates to an iterable or an iterator. Your specific proposal would break some perfectly valid code. You could likely come up with some symbols that couldn't show up in existing code, but it's usually better to use words instead of obscure symbol notation to preserve the readability of Python rather than letting it devolve into a concise, yet unreadable soup of symbols like Perl. On Tue, Feb 14, 2017 at 3:06 PM, Mikhail V <mikhailwas@gmail.com> wrote:

for i in range(...) is *sometimes* indicative of code smell, especially when then doing x[i], though it has its uses. I've never had a need to shorten a for...range line though. Other than it being "cute", do you have an example where it's definitively better? On Tue, Feb 14, 2017 at 4:03 PM, Todd <toddrjen@gmail.com> wrote:

Make some shim object that you can index into to get that functionality, could even call it Z (for the set of all integers). Short, and requires no new syntax. class IndexableRange: def __getitem__(self, item): if isinstance(item, slice): start = item.start if item.start is not None else 0 step = item.step if item.step is not None else 1 if item.stop is None: return itertools.count(start, step) else: return range(start, item.stop, step) else: return item Z = IndexableRange() for y in Z[0:10:2]: print(y) On Tue, Feb 14, 2017 at 5:22 PM, Mikhail V <mikhailwas@gmail.com> wrote:

On 15 February 2017 at 00:41, Nick Timkovich <prometheus235@gmail.com> wrote:
l can, also just make function r(a,b,c) : return range(a,b,c) for example, will look similar. Initially I was by the idea to remove brackets from for statement. Now after looking more at examples I realize what the real issue with the look is. Namely it is the word "in" itself. It is simply too short and that makes a lot of space holes in the lines. And letters 'i' and 'n' sort of suck from readability POV. E.g. compare: for x in 1,10,2: and for x over 1,10,2 : So the latter actually would make it look nicer. But that would probably be even less probable to be implemented. Mikhail

I would be surprised if this hasn't been suggested many times before. It's similar to Matlab's syntax: for x = start:step:finish <do whatever> end Any such change would represent a large departure from normal python syntax for dubious gain. In general, you can put any expression after the `in` keyword so long as it evaluates to an iterable or an iterator. Your specific proposal would break some perfectly valid code. You could likely come up with some symbols that couldn't show up in existing code, but it's usually better to use words instead of obscure symbol notation to preserve the readability of Python rather than letting it devolve into a concise, yet unreadable soup of symbols like Perl. On Tue, Feb 14, 2017 at 3:06 PM, Mikhail V <mikhailwas@gmail.com> wrote:
participants (6)
-
Abe Dillon
-
Mikhail V
-
MRAB
-
Nick Timkovich
-
Todd
-
Zachary Ware