How come string.maketrans does not work in Python 3.1?

前端 未结 10 2251
生来不讨喜
生来不讨喜 2020-12-18 19:49

I\'m a Python newbie.

How come this doesn\'t work in Python 3.1?

from string import maketrans   # Required to call maketrans function.

intab = \"aei         


        
10条回答
  •  醉梦人生
    2020-12-18 20:08

    Stop trying to learn Python 3 by reading Python 2 documentation.

    intab = 'aeiou'
    outtab = '12345'
    
    s = 'this is string example....wow!!!'
    
    print(s.translate({ord(x): y for (x, y) in zip(intab, outtab)}))
    

提交回复
热议问题