Not. NumPy arrays do , but standard python lists do not. However, the implementation of numpy arrays is not what you expect: they do not take a predicate, but evaluate each element, converting them to logical ones.
Edit : any and all exist as functions (and not as methods), but they do not use predicates, but treat logical values โโas numpy methods.
In Python, some might be:
def some(list_, pred): return bool([i for i in list_ if pred(i)])
You can implement every :
def every(list_, pred): return all(pred(i) for i in list_)
Edit : dumb sample:
every(['a', 'b', 'c'], lambda e: e == 'b') some(['a', 'b', 'c'], lambda e: e == 'b')
Try them urself
Luis masuelli
source share