Help with this code

José Manuel Suárez Sierra josemsuarezsierra at
Mon Jan 9 08:08:51 EST 2017

Hello, I am trying to make a code wich compares between 2 or several sequences (lists). It compares every element in a list with another list elements. For example, if we have a list_a=["a","b","c","d"] and list_b=["a","b"] I want to obtain a new list_c containing elements that match between these lists (a and b here), but, if for instance list_b were ["a","c"] the program must not store this data because they are not in same order.

Said this, I wrote this code but it doesnt work:

if __name__ == "__main__":

    def compare(a, b):

        i = 0
        j = 0
        c1 = []

        while a[i] == b[j]:
                j = j+1

        return c1

    cadena_1=raw_input("Introduce list 1 \n")
    cadena_2 = raw_input("Introduce list 2 \n")

    transf2 = list(cad_2)

    print compare(transf1,transf2)

Thank you

More information about the Python-list mailing list