On Feb 25, 8:12 pm, [EMAIL PROTECTED] wrote:
> consider the following working loop where Packet is a subclass of
> list, with Packet.insert(index, iterable) inserting each item in
> iterable into Packet at consecutive indexes starting at index.
>
>     i=0
>     while(i<len(packet)-4):
>         if packet[i:i+5]==Packet("01110"):
>             packet.insert(i, "01111")
>             i+=10 #skip the 5 bits inserted, and skip the 5 bits just
> checked bc overlap should not trigger insertion
>         else: i+=1
>
> is there a way to do this more elegantly?  seems like a big kludge.

Unless I missed something, this is a simple string replacement:

''.join(packet).replace('01110', '0111001111')


George

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to