User Tools

Site Tools


python:intersect_lists_but_preserve_order

Intersect lists but preserve the order

{tags: intersection without changing order}

In [1]:
required = ['c', 'b', 'a']; available = ['a', 'b', 'd']
required_and_available = [x for x in required if x in available]

In [2]:
required_and_available
Out[2]:
['b', 'a']
python/intersect_lists_but_preserve_order.txt · Last modified: 2024/08/07 19:40 by raju