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`, the above function can be simplified
```python
def yell(*words):
uppercased = map(str.upper, words)
print(*uppercased)
- using list comprehension, it can be turned into a one-liner
uppercased = [arg.upper() for arg in words]
- similarly, for a dictionary:
students = [
{"name": "Hermione", "house": "Gryffindor"},
{"name": "Harry", "house": "Gryffindor"},
{"name": "Ron", "house": "Gryffindor"},
{"name": "Draco", "house": "Slytherin"},
]
gryffindors = []
for student in students:
if student["house"] == "Gryffindor":
gryffindors.append(student["name"])
for gryffindor in sorted(gryffindors):
print(gryffindor)
- list comprehension can simplify this
griffindoes = [student for student in students if student["house"] == "Griffindor"]