Single integer to multiple integer translation in Python -
i'm trying translate single integer input multiple integer output, , using transtab function. instance,
intab3 = "abcdefg" outtab3 = "abcdefg" trantab3 = maketrans(intab3, outtab3)
is basic version of i'm doing. i'd able have input single letter , output multiple letters. like:
intab4 = "abc" outtab = "yes,no,maybe"
but commas , quotation marks don't work. keeps saying :
valueerror: maketrans arguments must have same length
is there better function should using? thanks,
you can use dict here:
>>> dic = {"a":"yes", "b":"no", "c":"maybe"} >>> strs = "abcd" >>> "".join(dic.get(x,x) x in strs) 'yesnomaybed'
Comments
Post a Comment