PEP 276 Simple Iterator for ints

Kerim Borchaev warkid at storm.ru
Thu Nov 29 06:45:32 EST 2001


Hello James,
Thursday, November 29, 2001, 5:18:43 AM, you wrote:
Jic> Peter Hansen wrote:
>>Or just:
>>
>>if not 0 <= index < len(mylist):
>>    print 'index out of range'

Jic> Right.  Which has the added advantage of not repeating index.

Why not just _use_ that index on the list to check whether it's valid?

try:
    mylist[index]
except IndexError:
    print 'index out of range'

Best regards,
 Kerim                            mailto:warkid at storm.ru






More information about the Python-list mailing list