<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Feb 1, 2015 at 10:13 AM, Todd <span dir="ltr"><<a href="mailto:toddrjen@gmail.com" target="_blank">toddrjen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">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.</p>
<p dir="ltr">The syntax I propose is simply to wrap a slice in parentheses. For examples, the following pairs are equivalent:</p>
<p dir="ltr">range(4, 10, 2)<br>
(4:10:2)</p>
<p dir="ltr">range(3, 7)<br>
(3:7)</p>
<p dir="ltr">range(5)<br>
(:5)</p>
<p dir="ltr">This syntax should not be easily confused with any existing syntax. Slices of sequences use square brackets, dictionaries use curly braces, and function annotations only appear in function declarations. It is also considerably more compact than the current range syntax, while still being similar to a syntax (slicing) all python users should be familiar with.</p></blockquote><div>It may be too late for this, but I like it. We can also elide extra parentheses inside calls, like with generator expressions:</div><div>sum(4:10:2)</div><div><br></div><div>Also, using list comprehension to generator expression analogy, we can have</div><div>[4:10:2]</div><div>which produces a list instead of a range object. Other than for completeness this does not seem very useful, though.</div><div><br></div><div><br></div><div>Eugene </div></div></div></div>