mercredi 2 décembre 2015

Comparing two lists item by item

I have 2 lists and I want to compare these lists item-by-item. For example:

a = [1,2,3]
b = [2,3,1]
for i in a:
    if i in b:
        pass # do something
    else:
        pass # do something else instead

I find this implementation a bit trivial.

I would like to know other ways of efficiently achieving the task.
(Efficiency implies either time complexity or space complexity)

Aucun commentaire:

Enregistrer un commentaire