Re: looping question 4 NEWB

2006-07-09 Thread manstey
Thanks Marc, that was very helpful. Marc 'BlackJack' Rintsch wrote: In [EMAIL PROTECTED], manstey wrote: I often have code like this: data='asdfbasdf' find = (('a','f')('s','g'),('x','y')) for i in find: if i[0] in data: data = data.replace(i[0],i[1]) is there a

looping question 4 NEWB

2006-07-06 Thread manstey
Hi, I often have code like this: data='asdfbasdf' find = (('a','f')('s','g'),('x','y')) for i in find: if i[0] in data: data = data.replace(i[0],i[1]) is there a faster way of implementing this? Also, does the if clause increase the speed? Thanks, Matthew --

Re: looping question 4 NEWB

2006-07-06 Thread Roel Schroeven
manstey schreef: Hi, I often have code like this: data='asdfbasdf' find = (('a','f')('s','g'),('x','y')) for i in find: if i[0] in data: data = data.replace(i[0],i[1]) is there a faster way of implementing this? Also, does the if clause increase the speed? I think this is

Re: looping question 4 NEWB

2006-07-06 Thread Wolfram Kraus
On 06.07.2006 12:43, manstey wrote: Hi, I often have code like this: data='asdfbasdf' find = (('a','f')('s','g'),('x','y')) for i in find: if i[0] in data: data = data.replace(i[0],i[1]) is there a faster way of implementing this? Also, does the if clause increase the

Re: looping question 4 NEWB

2006-07-06 Thread manstey
But what about substitutions like: 'ab' 'cd', 'ced' 'de', etc what is the fastest way then? Roel Schroeven wrote: manstey schreef: Hi, I often have code like this: data='asdfbasdf' find = (('a','f')('s','g'),('x','y')) for i in find: if i[0] in data: data =

Re: looping question 4 NEWB

2006-07-06 Thread bearophileHUGS
manstey: is there a faster way of implementing this? Also, does the if clause increase the speed? I doubt the if increases the speed. The following is a bit improved version: # Original data: data = 'asdfbasdf' find = (('a', 'f'), ('s', 'g'), ('x', 'y')) # The code: data2 = data for pat,rep

Re: looping question 4 NEWB

2006-07-06 Thread Roel Schroeven
manstey schreef: Roel Schroeven wrote: manstey schreef: I often have code like this: data='asdfbasdf' find = (('a','f')('s','g'),('x','y')) for i in find: if i[0] in data: data = data.replace(i[0],i[1]) is there a faster way of implementing this? Also, does the if clause

Re: looping question 4 NEWB

2006-07-06 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], manstey wrote: I often have code like this: data='asdfbasdf' find = (('a','f')('s','g'),('x','y')) for i in find: if i[0] in data: data = data.replace(i[0],i[1]) is there a faster way of implementing this? Also, does the if clause increase the speed?

Re: looping question 4 NEWB

2006-07-06 Thread Simon Forman
[EMAIL PROTECTED] wrote: manstey: is there a faster way of implementing this? Also, does the if clause increase the speed? I doubt the if increases the speed. The following is a bit improved version: # Original data: data = 'asdfbasdf' find = (('a', 'f'), ('s', 'g'), ('x', 'y')) #