Multiple string replacement...

Mikael Olofsson mikael at isy.liu.se
Fri Sep 22 10:09:07 EDT 2000


On 22-Sep-00 Simon Brunning wrote:
 >  I set up a ROT13 replacement set, which looks like:
 >  [['A', 'N'], ['B', 'O'], ['C', 'P'], ['D', 'Q'], ['E', 'R'], ['F', 'S'],
 >  ['G', 'T'], ['H', 'U'], ['I', 'V'], ['J', 'W'], ['K', 'X'], ['L', 'Y'],
 >  ['M', 'Z'], ['N', 'A'], ... and so on. The problem here is that after 'A'
 >  and been replaced by 'N', it gets replaced back again.

If translating single characters is what you really want to do, take a 
look at module string, and especially 

  string.maketrans(from,to)
  string.translate(s,table[,deletechars])

HTH

/Mikael

-----------------------------------------------------------------------
E-Mail:  Mikael Olofsson <mikael at isy.liu.se>
WWW:     http://www.dtr.isy.liu.se/dtr/staff/mikael               
Phone:   +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
Date:    22-Sep-00
Time:    16:06:22

         /"\
         \ /     ASCII Ribbon Campaign
          X      Against HTML Mail
         / \

This message was sent by XF-Mail.
-----------------------------------------------------------------------



More information about the Python-list mailing list