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 -- http://mail.python.org/m

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 th

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 > increa

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: > >

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? A

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 th

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', '

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]) >