str.translate gives TypeError - Translate takes one argument (2 given), worked in Python 2

前端 未结 5 1970
春和景丽
春和景丽 2020-11-29 00:24

I have the following code

import nltk, os, json, csv, string, cPickle
from scipy.stats import scoreatpercentile

lmtzr = nltk.stem.wordnet.WordNetLemmatizer         


        
5条回答
  •  温柔的废话
    2020-11-29 01:06

    Python 3.0:

    text = text.translate(str.maketrans('','','1234567890'))
    

    static str.maketrans(x[, y[, z]])

    This static method returns a translation table usable for str.translate().

    If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters (strings of length 1) to Unicode ordinals, strings (of arbitrary lengths) or None. Character keys will then be converted to ordinals.

    If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.

    https://docs.python.org/3/library/stdtypes.html?highlight=maketrans#str.maketrans

提交回复
热议问题