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
--
http
On May 4, 4:54 pm, "Gabriel Genellina" wrote:
> En Mon, 04 May 2009 15:12:41 -0300, mzdude 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
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 replace2(da
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 all
En Mon, 04 May 2009 15:12:41 -0300, mzdude 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 = "\0x%d\0x%d"
On May 4, 9:01 am, 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.
> > A
On Mon, 4 May 2009, Francesco Guerrieri wrote:
> On Mon, May 4, 2009 at 3:01 PM, John O'Hagan 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'
In article ,
=?ISO-8859-1?Q?Matthias_Gall=E9?= 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
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", c
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
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
On Mon, May 4, 2009 at 3:01 PM, John O'Hagan 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 ['a','c']
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', '
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
14 matches
Mail list logo