I have two lists: one containing a list of tuples (numbers) and the other the list of numbers. For instance, L = [(2,3),(5,6), (4,6),…] and E = [2,5,7,3…]. Now, are there any other better ways to do similar to the following?
The desired result is not well defined in your example. Your version produces empty tuples or doubled entries in the result depending on values in L and E.
Here are two variants:
filter( x -> x[1] in E, L)
But depending on you data and size this may be much slower as your version.
If E can be sorted there is also:
filter( x -> insorted(x[1],E), L)
which will be much faster if E is sorted.
The best solution depends on what you really want as a result and the sizes of L and E.