From 785380a77801ef60d22d8bfdf97b41f87ef04da7 Mon Sep 17 00:00:00 2001 From: Kyle K Date: Sun, 1 Nov 2020 19:16:28 -0600 Subject: lambda in python --- datatypes.py | 6 ++++++ lambda.py | 3 +++ 2 files changed, 9 insertions(+) create mode 100644 lambda.py diff --git a/datatypes.py b/datatypes.py index 8072582..5df78f3 100755 --- a/datatypes.py +++ b/datatypes.py @@ -31,3 +31,9 @@ print(x) mysum = sum([i for i in range(1, 10) if i%2==0]) squares = [x**2 for x in range(10)] squares = list(map(lambda x: x**2, range(10))) + + +# in addition to [] index operator on lists, there's slice operator: [start:stop:step] +aList = [1, 4, 9, 16, 25] +slicedList = aList[::-1] +print(f"reverse of: {aList} is: {slicedList}") diff --git a/lambda.py b/lambda.py new file mode 100644 index 0000000..7994376 --- /dev/null +++ b/lambda.py @@ -0,0 +1,3 @@ +fib = lambda n: n if n<=1 else fib(n-1)+fib(n-2) + +for i in range(10):print(fib(i)) \ No newline at end of file -- cgit v1.2.3