Difference between revisions of "Python: Lambda and List Comprehensions"
From MyWiki
Line 2: | Line 2: | ||
my_function = lambda a, b, c : a + b | my_function = lambda a, b, c : a + b | ||
my_function(1, 2, 3) | my_function(1, 2, 3) | ||
+ | |||
+ | # We will replace the following with a List Comprehension | ||
+ | my_list = [] | ||
+ | for number in range(1,1000): | ||
+ | if number %2 == 0: | ||
+ | my_list.append(number) | ||
+ | |||
+ | my_list | ||
</source> | </source> |
Revision as of 11:18, 28 July 2019
my_function = lambda a, b, c : a + b my_function(1, 2, 3) # We will replace the following with a List Comprehension my_list = [] for number in range(1,1000): if number %2 == 0: my_list.append(number) my_list