Skip to content

Instantly share code, notes, and snippets.

@hanksudo
Last active August 29, 2015 14:13
Show Gist options
  • Save hanksudo/7034afa77f9abf392693 to your computer and use it in GitHub Desktop.
Save hanksudo/7034afa77f9abf392693 to your computer and use it in GitHub Desktop.
Python lambda practice 1
# method 1
x = [2, 3, 4, 5, 6]
y = []
for v in x:
y += [v*5]
assert x == [2, 3, 4, 5, 6]
assert y == [10, 15, 20, 25, 30]
# method 2
y = [v * 5 for v in x]
assert y == [10, 15, 20, 25, 30]
# labmda way
y = map(lambda v: v * 5, x)
assert y == [10, 15, 20, 25, 30]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment