find sublist inside list

Aahz aahz at pythoncraft.com
Mon May 4 12:25:17 EDT 2009


In article <gtmlsk$q51$1 at amma.irisa.fr>,
=?ISO-8859-1?Q?Matthias_Gall=E9?=  <mgalle at irisa.fr> wrote:
>
>My problem is to replace all occurrences of a sublist with a new element.
>
>Example:
>Given ['a','c','a','c','c','g','a','c'] I want to replace all 
>occurrences of ['a','c'] by 6 (result [6,6,'c','g',6]).

What's your goal?  After you do this once, you cannot repeat the
operation with a different sublist because you are not tracking the
source of the numbers.  You might look into standard compression
algorithms for information about how to accomplish this.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan



More information about the Python-list mailing list