forked from imteekay/functional-programming-learning-path
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintro.py
More file actions
31 lines (24 loc) · 604 Bytes
/
intro.py
File metadata and controls
31 lines (24 loc) · 604 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Assign functions to a variable
def add(a, b):
return a + b
plus = add
value = plus(1, 2)
print(value) # 3
# Lambda
value = (lambda a, b: a + b)(1, 2)
print(value) # 3
addition = lambda a, b: a + b
value = addition(1, 2)
print(value) # 3
authors = [
'Octavia Butler',
'Isaac Asimov',
'Neal Stephenson',
'Margaret Atwood',
'Usula K Le Guin',
'Ray Bradbury'
]
sorted_authors_by_name_length = sorted(authors, key=len)
print(sorted_authors_by_name_length)
sorted_authors_by_last_name = sorted(authors, key=lambda name: name.split()[-1])
print(sorted_authors_by_last_name)