-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello_loops.py
49 lines (39 loc) · 1.19 KB
/
hello_loops.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def print_phrases():
"""
Print Monty-Python phrases to the console.
:return: None
"""
phrases = (
"Nobody expects the Spanish Inquisition!",
"'Tis but a scratch!",
"And now for something completely different...",
"My hovercraft is full of eels",
"I fart in your general direction!",
"She's got huge... tracts of land"
)
for phrase in phrases:
print(phrase)
def print_users():
"""
Print user dictionary to the console, before and after manipulation by a for loop.
:return: None
"""
users = {
"gchapman": "inactive",
"jcleese": "active",
"tgilliam": "active",
"eidle": "active",
"tjones": "inactive",
"mpalin": "active"
}
# initial implementation of concatenation in print function:
# print("BEFORE: " + users.__str__())
# but Python can do this - and it reads much better
print("BEFORE:", users)
# copy the dictionary for iteration, but make changes to the original
for user, status in users.copy().items():
if status == "inactive":
del users[user]
print("AFTER:", users)
print_phrases()
print_users()