Functional Programming in Python
Contents
Functional programming can also be interesting in Python. Here are some useful snippets.
Lambda
A lambda expression is an anonymous function.
|
Map
map
is a higher-order function that allows to apply a function to every element in an iterable
object and it returns itself an iterable
.
|
Filter
The filter function tests each element in an iterable
object with a function that returns either True
or False
.
|
Reduce
Apply function of two arguments cumulatively to the items of sequence, from left to right, so as to reduce the sequence to a single value.
|
Head & Tail
head
and tail
are idiomatic of functional programming languages.
|
List Comprehension
|
Any and All
Check if any
or all
conditions are met.
They can also be seen as series of logical or
and and
operators, respectively.
|