Skip to content

Instantly share code, notes, and snippets.

@vtemian
Last active August 31, 2017 17:25
Show Gist options
  • Save vtemian/d7488d413309ec4b3563cf2c490095fc to your computer and use it in GitHub Desktop.
Save vtemian/d7488d413309ec4b3563cf2c490095fc to your computer and use it in GitHub Desktop.
Functional
def sum_squared_array(a):
for index in range(len(a)):
a[index] = a[index] * a[index]
for index in range(len(a)):
total_not_functional += a[index]
total_not_functional = 0
sum_squared_array([1, 2, 3, 4])
total_function = reduce(lambda element, collector: collector + element,
map(lambda x: x ** 2, [1, 2, 3, 4]), 0)
total_function_simple = sum(map(lambda x: x ** 2, [1, 2, 3, 4]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment