Added files for Ecoanova's Python 3 course.

This commit is contained in:
2019-12-07 20:09:13 -04:00
committed by GitHub
parent 3a24267742
commit 6bf8ac0e01
29 changed files with 604 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
################################
# Lambda (anonymous) functions #
################################
f = lambda x, y: x + y
print(f(1, 2))
print()
##########################
# Higher order functions #
##########################
# Map: Applies a function to many lists. Returns a generator.
for i in map(lambda x: x*x, [1, 2, 3, 4, 5, 6]):
print(i)
print()
for i in map(f, [1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6, 7]):
print(i)
print()
# Custom higher order function
def hof(function = lambda x: x, *args):
for a in args:
print(function(a))
hof(lambda s: s.upper(), "a", "b", "c")
print()
hof(lambda x: x is None, 1, ["a", "b"], None, {})