why won't slicing lists raise IndexError?

Chris Angelico rosuav at gmail.com
Mon Dec 4 17:29:48 EST 2017


Against my better judgement, I'm going to ask...

On Tue, Dec 5, 2017 at 9:22 AM, Rick Johnson
<rantingrickjohnson at gmail.com> wrote:
> Terry Reedy wrote:
>
> [...]
>
>> try:
>>      item = seq[n]
>> except IndexError
>>      do_without_item()
>> else:
>>      process(item)
>>
>> item = seq[n:n+1]
>> if item:
>>      process(item)
>> else:
>>      do_without_item()
>>
>> Many prefer the second.
>
> And they'll prefer it even more when they realize the entire ELSE
> clause of your latter example is superfluous.

... how is it superfluous?

ChrisA



More information about the Python-list mailing list