December 25th, 2013, 01:13 PM
Create a sublist of a list of list
Hello everyone and happy Christmas !
Here is my problem (I am a Python newbie):
I have a list of list which consists of the following
I have another list which only contains a subset of labels e.g.
I want to create a subset of L1 only for the labels contained in L2.i
Any idea on how to proceed ?
December 25th, 2013, 02:50 PM
L3 = [A for A in L1 if A in L2]
# if the lists are long be sure to use sets.
KEYS = set(L2)
L3 = [A for A in L1 if A in KEYS]
[/code] are essential for python code and Makefiles!
December 25th, 2013, 04:03 PM
Thanks. Works great. I still have to understand the subtilities of this great language