Switching python to a functional style.

Made this code a functional style as it is shorter.