3-1-3-32. Quiz: List Comprehensions

Quiz: Extract First Names

Use a list comprehension to create a new list first_names containing just the first names in names in lowercase.

names = ["Rick Sanchez", "Morty Smith", "Summer Smith", "Jerry Smith", "Beth Smith"]

first_names = # write your list comprehension here
print(first_names)

Quiz: Multiples of Three

Use a list comprehension to create a list multiples_3 containing the first 20 multiples of 3.

multiples_3 = # write your list comprehension here
print(multiples_3)

Quiz: Filter Names by Scores

Use a list comprehension to create a list of names passed that only include those that scored at least 65.

scores = {
             "Rick Sanchez": 70,
             "Morty Smith": 35,
             "Summer Smith": 82,
             "Jerry Smith": 23,
             "Beth Smith": 98
          }

passed = # write your list comprehension here
print(passed)

Dr. Serendipity에서 더 알아보기

지금 구독하여 계속 읽고 전체 아카이브에 액세스하세요.

Continue reading