'Merge strings from a PO file and a Py file'

def merge_strings(self, postrings, pystrings, preference):

    lim_po = len(postrings)
    lim_py = len(pystrings)
    i = 0
    j = 0
    extra = []
    eappend = extra.append
    while ((i < lim_py) and (j < lim_po)):
        if (pystrings[i][0] < postrings[j][0]):
            if (preference == False):
                eappend(pystrings[i])
            i += 1
        elif (pystrings[i][0] > postrings[j][0]):
            j += 1
        else:
            if preference:
                if (postrings[j][1] and (not postrings[j][1].startswith('***'))):
                    pystrings[i] = postrings[j]
            elif (pystrings[i][1] and (not pystrings[i][1].startswith('***'))):
                postrings[j] = pystrings[i]
            i += 1
            j += 1
    if preference:
        return pystrings
    else:
        while (i < lim_py):
            extra.append(pystrings[i])
            i += 1
        for st in extra:
            postrings.append(st)
        postrings.sort(key=(lambda tup: tup[0]))
        return postrings
