I am still a beginner at coding, especially with python. In one of my freshman classes, we were introduced to racket, a functional programming language very similar to scheme. In this class we learned about the functions andmap
and ormap
.
Is there a built in andmap
and ormap
in Python?
Python has the map
function that applies a function to a sequence plus all
and any
that perform the and
and or
functions. These short-circuit as soon as their condition is violated.
any(map(somefunction, sequence))
all(map(somefunction, sequence))
Python also lets you iterate and apply functions to a sequence directly in the language
any(somefunction(x) for x in sequence)
all(somefunction(x) for x in sequence)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With