Rita Sue and Bob too

Nicolas Ernotte nicolas.ernotte at advalvas.be
Fri Aug 20 11:56:10 EDT 2004


Grégoire Dooms wrote:
> This second piece of code searches list for the sequence 
> ['Rita','Sue','Bob'] in this order and without inserts.
> It can be rewritten in a more pythonic way :
> 
> for i in range(len(l)):
>     if l[i:i+3] == ['Rita','Sue','Bob']:
>         print 'They were found'
>         break
> else:
>     print 'They were not in the list'

Décidément, le monde est petit !

Nicolas Ernotte, FSA12 ;-)



More information about the Python-list mailing list