I have the following code
import nltk, os, json, csv, string, cPickle
from scipy.stats import scoreatpercentile
lmtzr = nltk.stem.wordnet.WordNetLemmatizer
This is how translate works:
yourstring.translate(str.maketrans(fromstr, tostr, deletestr))
Replace the characters in fromstr
with the character in the same position in tostr
and delete all characters that are in deletestr
. The fromstr
and tostr
can be
empty strings and the deletestr
parameter can be omitted.
example:
str="preetideepak12345aeiou"
>>> str.translate(str.maketrans('abcde','12345','p'))
output:
'r55ti4551k1234515iou'
here:
a is translated to 1
b is translated to 2
c is translated to 3 and so on
and p is deleted from string.