Last active
October 11, 2015 12:17
-
-
Save andreagrandi/e200f8129840ea945258 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define a lambda function that takes a number and double it | |
d = lambda x: x * 2 | |
# Create a list containing: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | |
l1 = [x for x in xrange(10)] | |
# Method #1 using map(...) | |
# output: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18] | |
print map(d, l1) | |
# Method #2 using list comprehension | |
# output: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18] | |
print [d(x) for x in l1] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment