File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ ## Schedule and Outline
2
+ 1 . [ lambda.py] ( https://github.com/kevinlu1248/ccc_python_lessons/tree/master/Lesson%203/lambda.py ) : (5 minutes) Introduce lambda function to them
3
+ 2 . (Remainder of the time) Try doing https://dmoj.ca/problem/ccc18s2 and https://dmoj.ca/problem/ccc16j2 using the input mechanics discussed!
4
+
5
+ ** Note that each of the Python file's teaching materials can be found in the Lesson 1 repository at:**
6
+ https://github.com/kevinlu1248/ccc_python_lessons/tree/master/Lesson%202
Original file line number Diff line number Diff line change
1
+ # Lambda Introduction
2
+ # Kevin Lu
3
+
4
+ # WARMUP QUESTION
5
+ # take a string of space-seperated integers '1 2 3 4 5' and return every integer squared
6
+ # try doing this semi-code-golf: try using less but maintaining clarity
7
+
8
+ # ANSWER (using list comprehension)
9
+ def square (s ):
10
+ return ' ' .join ([str (int (i ) ** 2 ) for i in s .split ()])
11
+ print (square ('1 2 3 4 5' ))
12
+
13
+ # an alternative way to do this is to simply use lambda
14
+ def square (s ):
15
+ return ' ' .join (map (lambda i : str (int (i ) ** 2 ), s .split ()))
16
+ print (square ('1 2 3 4 5' ))
17
+
18
+ # So what is lambda?
19
+ # lambda is what's called an anonymous function, which is by definition an unnamed function
20
+ # furthermore, it can also be used as a shorthand
21
+
22
+ # so lets first look a simple usage of it to subsitute a function
23
+ test
You can’t perform that action at this time.
0 commit comments