problem 6 solution

trying to follow the python version i.e anonymous functions.