Would be nice to have something like the Maybe-Monad in the functools package for example. Sometimes python's None is a valid output and can not be used equivalently to Nothing.
What I like to do is to break down my problem into only functions and then build up objects from them. This way I can reduce the tests around the object and easier test the functions.
Constructive feedback:
I think you could have added, that map and filter return you a genrator. You wrap them in your examples in list( ... ) and get the same result as in the list comprehensions.
A cool thing to use is the operator module. Then you can do something like this:
from operator import add, mul
from functools import reduce
print(reduce(add, [1,2,3,4]))
# => 10
print(reduce(mul, [1,2,3,4]))
# => 24
This reduces the amount of simple lambda functions like lambda x, y: x + y and makes the code more readable.
Cleanly written, I really like that 👍
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Would be nice to have something like the Maybe-Monad in the
functools
package for example. Sometimes python'sNone
is a valid output and can not be used equivalently toNothing
.What I like to do is to break down my problem into only functions and then build up objects from them. This way I can reduce the tests around the object and easier test the functions.
Constructive feedback:
I think you could have added, that
map
andfilter
return you agenrator
. You wrap them in your examples inlist( ... )
and get the same result as in the list comprehensions.A cool thing to use is the
operator
module. Then you can do something like this:This reduces the amount of simple lambda functions like
lambda x, y: x + y
and makes the code more readable.