Rita Sue and Bob too
Paul Rubin
http
Thu Aug 19 22:19:39 EDT 2004
"M. Clift" <noone at here.com> writes:
> But, how to I find a sequence in a list of unknown size? i.e. this sequence
> in list of other names and replace it with three others?
>
> 'Rita','Sue','Bob'
>
> This is almost a nightly occurrence (my posting questions), but I am
> learning : )
You have to scan through the list and look for that sequence, e.g.
for i in xrange(len(mylist) - 2):
if mylist[i:i+3] == ['Rita','Sue','Bob']:
print 'They were found'
break
There are fancier and more efficient ways to scan the list, but this
is the basic idea.
More information about the Python-list
mailing list