I need to replace some letters into a List with numbers (each letter is encoded to a number). I used this structure:
r = []
for x in some_list:
if x in "ABCDE":
r.append({"A":10, "B":20, "C":30, "D":40, "E":50}[x])
else:
r.append(int(x)) # convert string digit to digit
some_list = r
(some_list being mutable as in this code).
I wish to ask if there are some more compact structures in python (less code) that can make this encoding and run faster.
How about
Other ways to write that list comprehension include: