-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
35 lines (19 loc) · 780 Bytes
/
main.py
File metadata and controls
35 lines (19 loc) · 780 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
32
33
34
35
from functools import reduce
# 1 Capitalize all the pet names and print the list
my_pets = ['sisi', 'bibi', 'titi', 'carla']
def caps(items):
return items.upper()
print(list(map(caps, my_pets)))
# 2 Zip the 2 lists into a list of tuples, but sort the numbers from lowest to highest.
my_strings = ['a', 'b', 'c', 'd', 'e']
my_numbers = [5, 4, 3, 2, 1]
print(list(zip(my_strings, my_numbers)))
# 3 Filter the scores that pass over 50%
scores = [73, 20, 65, 19, 76, 100, 88]
def fil_ter(x):
return x > 50
print(list(filter(fil_ter, scores)))
# 4 Combine all the numbers that are in a list on this file using reduce (my_numbers and scores). What is the total?
def accumulator(acc, item):
return acc + item
print(reduce(accumulator, (my_numbers + scores)))