Suggested feature: slice syntax within tuples (or even more generally)?

Ian Kelly ian.g.kelly at gmail.com
Mon Feb 25 17:54:56 CET 2013


On Mon, Feb 25, 2013 at 12:41 AM, Andrew Robinson
<andrew3 at r3dsolutions.com> wrote:
>> Intuitively, it should result in an infinite loop starting at 0.  But
>> ranges require a stop value for a very good reason -- it should not be
>> this easy to accidentally create an infinite for loop.
>
> ...
> and, besides, the same is true with other constructions of loops....
>
> while a:  # Damn easy, if a is accidentally true!

Notice I specifically said an "infinite *for* loop".  While loops are
meant to be indeterminate in the number of iterations they will take
going into the loop; for loops are not.

>> The next problem you run into is that the semantics of negative
>> numbers are completely different between slices and ranges.  Consider
>> this code:
>>
>> s = (-5:6)
>> for i in s:
>>      print(i)
>> for i in range(6)[s]:
>>      print(i)
>
> I don't find this difference to be necessary, nor objectionable.
>
> It is less inconsistent, in my view, to allow that
> ([ 1,2,3,4,5 ])[-1:2]  produce [5,1,2] than an empty list;
> and ([ 1,2,3,4,5])[2:-1] does produce an empty list.
>
> I have been looking for actual programs that this would break for over two
> months now, and I haven't been finding any.  I am willing to run any
> mainstream application you can find on test-patched python!

Yes, I recollect now that we have already had this discussion.



More information about the Python-list mailing list