To start this lab, download this zip file.
Lab 15 - Coiteration
Activities
add_numbers.py
Write a function add_numbers(list_of_numbers1, list_of_numbers2) that adds each element of list_of_numbers1 and list_of_numbers2 pairwise and returns the results in an ordered list.
For example:
add_numbers([13, 4, 6], [1,8,13])
Would return:
[14, 12, 19]
compare_strings.py
Write a function compare_strings(string1, string2) where string1 and string2 are strings of the same length. If the characters of string1 and string2 match at a given position, replace it with ”*“. Otherwise replace it with ”.“.
For example:
compare_strings("potato","tomato")
Would return:
".*.***"
repeat_characters.py
Write a function repeat_characters(string, list_of_numbers) that takes a string and a list_of_numbers and creates a new string where each character is repeated the corresponding number of times.
For example:
repeat_characters("python",[3,6,2,5,8,1])
Would return:
"pppyyyyyytthhhhhoooooooon"
interweave_strings.py
Write a function interweave_strings(string1, string2, string3) that interweaves string1, string2, and string3.
For example:
interweave_strings("lemon", "water", "sugar")
Would return:
"lwseaumtgoeanrr"
least_of_three.py
Write a function least_of_three(list_of_numers1, list_of_numbers2, list_of_numbers3) where list_of_numbers1, list_of_numbers2, list_of_numbers3 all have the same length. For each position in the lists, find the smallest number out of the three. Return a list with the corresponding results.
For example:
least_of_three([1,4,6],[9,2,12],[7,8,9])
Would return:
[1,2,6]
best_restaurants.py
Write a function best_restaurants(restaurant_ratings) that returns a list of restaurant names with ratings greater than 4.
For example:
restaurant_ratings = [("Chili's", 3), ("McDonald's", 2), ("Five Guys", 4), ("Chipotle", 5), ("Taco Bell", 1), ("Chick-fil-a", 5), ("Panda Express", 4)]
best_restaurants(restaurant_ratings)
Would return:
["Chipotle", "Chick-fil-a"]
Grading
| Activity | Points |
|---|---|
add_numbers.py | 5 |
compare_strings.py | 5 |
repeat_characters.py | 5 |
interweave_strings.py | 5 |
least_of_three.py | 5 |
best_restaurants.py | 5 |