convert letters to numbers for a file in a list

I have read a file in a list which looks like this:


I want to convert the letters to numbers based on this dictionary:


I have done this:

with open("/Users/Downloads/test") as file_in:
    lines = []
    for line in file_in:
for line in lines:
    except KeyError:

however I get "header" printed every line Output

header header header header

Correct output:

header 13012... header 13012

Read more here:

Content Attribution

This content was originally published by Paolo Lorenzini at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: