Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
functional python - from hackernoon.com, lean functional python in 10 min
#python 2.7.12 # https://hackernoon.com/learn-functional-python-in-10-minutes-to-2d1651dece6f # map x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] def sqr(n): return n * n print list(map(sqr, x)) ## lambda - square = lambda num: num * num ## print square(2) print list(map(lambda num: num * num, x)) print # reduce product = 1 y = [1, 2, 3, 4] for num in y: product = product * num print product from functools import reduce product = reduce( (lambda a, b: a * b), [1, 2, 3, 4] ) print product print # filter r = range(-5, 5) new_list = [] for num in r: if num < 0: new_list.append(num) print new_list x = range(-5, 5) all_less_than_zero = list(filter(lambda num: num < 0, x)) print all_less_than_zero print #hof def summation(n): return sum(n) def action(func, numbers): return func(numbers) print(action(summation, [1, 2, 3])) print ''' def brandon(): return "brandon" def john() : return "john" def person(): age = int(input("What's your age?")) if age == 21: return brandon() else: return john() result = person() '''
run
|
edit
|
history
|
help
0
Crypto 123 - MD5
Rectangle Area
gameboy
Nama Bulan Python
GardenerList
tree generator
Fold an array
NormalizedTags
First programm
my first code