0
INPUT = ["a","b","c","d","e","f","g","h","i","j","k"]
OUTPUT = ["20","21","22","23","24","25","26","27","28","29","30"]
TABLE = maketrans(INPUT, OUTPUT)
content = content.translate(TABLE)

TypeError: maketrans() argument 1 must be string or read-only character buffer, not list

What I want is, for example, if string = "a", the return to be "20".

I cannot turn INPUT and OUTPUT into strings because they would have different size.

What is the most efficient alternative or tweak?

Naji Krayem
  • 83
  • 1
  • 2
  • 9

1 Answers1

0

Use a izip_longest (Python 2.x) or zip_longest (Python 3.x):

from itertools import izip_longest

INPUT = ["a","b","c","d","e","f","g","h","i","j","k"]
OUTPUT = ["20","21","22","23","24","25","26","27","28","29","30"]

string = 'a'   # string here

for i, o in izip_longest(INPUT, OUTPUT):
    if i == string:
        print(o)
# 20
Austin
  • 25,759
  • 4
  • 25
  • 48