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 speed? > > Thanks, > Matthew >
>>> import string >>> data='asdfbasdf' >>> data.translate(string.maketrans('asx', 'fgy')) 'fgdfbfgdf' HTH, Wolfram -- http://mail.python.org/mailman/listinfo/python-list