Python how to replace values in one list with values in a dictionary?

Viewed 10426

example:

my list is ['tree','world','tre','worl']

my dict is {'tre':'good','worl':nice}

my scripts:

def replace(list, dictionary):
    for i in list:
        for k in dictionary:
            list = list.replace(k, dictionary[k])
    return list
print replace(input_file,curaw_dict)

but every time I receive the result is like:

goode
niced
good
nice

how can I make it more accurate make it like

tree
world
good
nice

Thanks alot

6 Answers
Related