I have a list of numbers:
a = [3, 6, 20, 24, 36, 92, 130]
And a list of conditions:
b = ["2", "5", "20", "range(50,100)", ">120"]
I want to check if a number in 'a' meets one of the conditions in 'b' and if yes, put these numbers in list 'c'
In above case:
c = [20, 92, 130]
I created this code what seems to do what I want:
c = []
for x in a:
for y in b:
if "range" in y:
rangelist = list(eval(y))
if x in rangelist:
c.append(x)
elif ">" in y or "<" in y:
if eval(str(x) + y):
c.append(x)
else:
if x == eval(y):
c.append(x)
However my list 'a' can be very big.
Is there not an easier and faster way to obtain what I want?