use list comprehension in translate function instead of a for-loop