-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtutorial_26.py
More file actions
33 lines (25 loc) · 866 Bytes
/
tutorial_26.py
File metadata and controls
33 lines (25 loc) · 866 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
students = {
'tom': [80, 60, 75, 63],
'kate': [20, 89, 62, 80, -56],
'bill': [89, 57, 48, 60, 103]
}
names = {
'longer': 'jake',
'noodlehead': 'kimley',
'crutcher': 'ally'
}
# ex 1 - nested for loop
for grades in students.values():
for grade in grades:
print(grade)
# ex 2 - comprehensive list. add 3 to scores below 70
students['tom'] = [(g + 3 if g < 70 else g) for g in students['tom']]
# ex 3 - nested comprehensive list. get all valid grades
all_grades = [g for grades in students.values() for g in grades if g >= 0 and g <= 100]
class_avg = sum(all_grades) / len(all_grades)
print(class_avg)
# ex 4 - comprehensive sets
print( { char for char in 'Je1re2my' if not char.isdigit() } )
# ex 5 - comprehensive dictionaries
switcheroo = {first:last for first, last in zip(names.values(), names.keys())}
print(switcheroo)