I have an list/array, lets call it x, and I want to create a new list/array, lets call this one z, out of elements from x that match a
Python has a built-in filter function:
lst = [1, 2, 3, 4, 5, 6]
filtered = filter(lambda x: x < 5, lst)
But list comprehensions might flow better, especially when combining with map operations:
mapped_and_filtered = [x*2 for x in lst if x < 5]
# compare to:
mapped_and_filtered = map(lambda y: y*2, filter(lambda x: x < 5, lst))