![]() | 1 | initial version |
Maybe this example can help
L1=[1,2];L2=[-1,1];L3=[3,1];L=[L1,L2,L3]
[Li for Li in L if all(map(lambda v: v>0, Li))]
![]() | 2 | No.2 Revision |
Maybe this example can helpLearn about the Python command all
using help(all)
.
Below are a couple of examples.
First define a list of lists (of integers):
L1=[1,2];L2=[-1,1];L3=[3,1];L=[L1,L2,L3]
L1 = [1, 2]
L2 = [-1, 1]
L3 = [3, 1]
L = [L1, L2, L3]
Then keep only those consisting only of positive integers:
using map
:
[Li for Li in L if all(map(lambda v: v>0, v > 0, Li))]
using list comprehension:
[Li for Li in L if all(v > 0 for v in Li)]
For your use case, this might become
LL = [Li for Li in L if all(check(s) for s in Li)]