Matthias Gallé wrote:
Hi.
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]).
For novelty value:
from itertools import izip
def
On May 4, 4:54 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote:
En Mon, 04 May 2009 15:12:41 -0300, mzdude jsa...@cox.net escribió:
substring isn't limited to 0..255
substring = \0x%d\0x%d % (257,257)
'acaccgac'.replace(ac, substring)
John O'Hagan:
li=['a', 'c', 'a', 'c', 'c', 'g', 'a', 'c']
for i in range(len(li)):
if li[i:i + 2] == ['a', 'c']:
li[i:i + 2] = ['6']
Oh well, I have done a mistake, it seems.
Another solution then:
'acaccgac'.replace(ac, chr(6))
'\x06\x06cg\x06'
Bye,
bearophile
--
Hi.
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]).
If I do this with string ('acaccgac') I have the advantage of all the
'find'
Matthias Gallé:
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]).
There are several ways to solve this problem. Representing a string as
a
On Mon, 4 May 2009, Matthias Gallé wrote:
Hi.
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]).
li=['a', 'c', 'a', 'c', 'c', 'g', 'a',
On Mon, May 4, 2009 at 3:01 PM, John O'Hagan m...@johnohagan.com wrote:
On Mon, 4 May 2009, Matthias Gallé wrote:
Hi.
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
Matthias Gallé:
the int that can replace a sublist can be 255,
You didn't specify your integer ranges.
Probably there are many other solutions for your problem, but you have
to give more information. Like the typical array size, typical range
of the numbers, how much important is total memory
Matthias Gallé wrote:
bearophileh...@lycos.com wrote:
John O'Hagan:
li=['a', 'c', 'a', 'c', 'c', 'g', 'a', 'c']
for i in range(len(li)):
if li[i:i + 2] == ['a', 'c']:
li[i:i + 2] = ['6']
Oh well, I have done a mistake, it seems.
Another solution then:
'acaccgac'.replace(ac,
bearophileh...@lycos.com wrote:
John O'Hagan:
li=['a', 'c', 'a', 'c', 'c', 'g', 'a', 'c']
for i in range(len(li)):
if li[i:i + 2] == ['a', 'c']:
li[i:i + 2] = ['6']
Oh well, I have done a mistake, it seems.
Another solution then:
'acaccgac'.replace(ac, chr(6))
'\x06\x06cg\x06'
In article gtmlsk$q5...@amma.irisa.fr,
=?ISO-8859-1?Q?Matthias_Gall=E9?= mga...@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
On Mon, 4 May 2009, Francesco Guerrieri wrote:
On Mon, May 4, 2009 at 3:01 PM, John O'Hagan m...@johnohagan.com wrote:
On Mon, 4 May 2009, Matthias Gallé wrote:
Hi.
My problem is to replace all occurrences of a sublist with a new
element.
Example:
Given
On May 4, 9:01 am, Matthias Gallé mga...@irisa.fr wrote:
bearophileh...@lycos.com wrote:
John O'Hagan:
li=['a', 'c', 'a', 'c', 'c', 'g', 'a', 'c']
for i in range(len(li)):
if li[i:i + 2] == ['a', 'c']:
li[i:i + 2] = ['6']
Oh well, I have done a mistake, it seems.
En Mon, 04 May 2009 15:12:41 -0300, mzdude jsa...@cox.net escribió:
substring isn't limited to 0..255
substring = \0x%d\0x%d % (257,257)
'acaccgac'.replace(ac, substring)
'\x00x257\x00x257\x00x257\x00x257cg\x00x257\x00x257'
This isn't what you think it is. Look carefully:
py substring =
Matthias Gallé wrote:
Hi.
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]).
If I do this with string ('acaccgac') I have the advantage of
15 matches
Mail list logo