Python: replacement rules when relationship is not 1:1
===

I'm trying to implement replacement rules (or mapping) for numbers in a CSV file.

Some numbers in a list have a 1:1 relationship with numbers in another list, as in `123 -> 456`. An example of such a list, and its replacement rules, is the following:

    list1 = ["123", "456"]
    list2 = ["1234", "00456"]
    
    for i in list1:
        list1[list1.index(i)] = list2[list1.index(i)]

Where I encounter problems is in the case where a number from a list is associated to more than one number in another, as in:

    list1 = ["123", "123", "456"]
    list2 = ["a123", "1234", "00456"]

The following code doesn't work, but is what I've tried to make the replacement:

    def convSan(sfin, cfout):
        with open(sfin, "rb") as fin:
            with open(cfout, "wb") as fout:
                csvin = csv.reader(fin)
                csvout = csv.writer(fout, delimiter=",")
                fline = csvin.next()
                csvout.writerow(fline)
    
                for row in csvin:
                    if ce.codes1200i.count(row[25]) == 1:
                        row[25] = ce.codes1200r[ce.codes1200i.index(row[25])]
                        csvout.writerow(row)
                    else:
                        for i in range(ce.codes1200i.count(row[25])):
                            row[25] = ce.codes1200r[ce.codes1200i.index(row[25])+i] # take the next item in list
                            csvout.writerow(row)

When the function is called, it returns an error informing me that `x is not in list`.