-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyell.py
More file actions
65 lines (43 loc) · 1.13 KB
/
Copy pathyell.py
File metadata and controls
65 lines (43 loc) · 1.13 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# def main():
# yell("This is CS50")
# def yell(phrase):
# print(phrase.upper())
# if __name__ == "__main__":
# main()
# ## Integrating a list and unpacking
# def main():
# yell(["This", "is", "CS50"])
# def yell(words):
# uppercased = []
# for word in words:
# uppercased.append(word.upper())
# print(*uppercased)
# if __name__ == "__main__":
# main()
# ## More user friendly, adopting *args
# def main():
# yell("This", "is", "CS50")
# def yell(*words):
# uppercased = []
# for word in words:
# uppercased.append(word.upper())
# print(*uppercased)
# if __name__ == "__main__":
# main()
# ## Using 'map' which applies a function to each argument
# def main():
# yell("This", "is", "CS50")
# def yell(*words):
# uppercased = map(str.upper, words)
# print(*uppercased)
# if __name__ == "__main__":
# main()
## Using 'list comprehensions'
## This allows to create a list "on the fly"
def main():
yell("This", "is", "CS50")
def yell(*words):
uppercased = [word.upper() for word in words]
print(*uppercased)
if __name__ == "__main__":
main()