I have this string
message = '10100010011'
and this dictionary
codes = {97: '1', 98: '01', 107: '001', 114: '000'}
and I need to substitute the original message using the dictionary to something like this
[97, 98, 114, 97, 107, 97]
I tried my own way, which works, but when I use some REALLY large strings, it's just really slow. Is there any faster way to do this than this?
    codes = dict(zip(codes.values(), codes.keys()))
    decoded_mess = []
    pom = ""
    for i in message:
        pom += i
        if pom in codes:
            decoded_mess.append(codes[pom])
            pom = ""
I saw the answers here Easiest way to replace a string using a dictionary of replacements? and I tried that, but that did not work for me. Maybe because they are dealing with whole words, but I have 1 long string of 1s and 0s.
 
     
    