Instructions

Write a function number_pixels that consumes a list of lists of strings (representing an image) and a string colour. Your function should produce the number of entries that match colour.

Note:

Hints:

  • Use a loop to process each list in the input.

For the class Meal, write a method contains such that dinner.contains("eggs") produces True if the object dinner contains the string "eggs" in its list of allergens and False otherwise.

Note:

Hint:

  • You can use in to determine if an item is in a list.

Now create a function (not a method) all_contain that consumes a list of Meal objects and a string allergen. Your function should produce a list of the names of all objects in the list that contain the string in their allergen list.

Note:

Hints:

  • Make sure that your function definition is not part of the class definition.

Write a function code that consumes a string and a dictionary such that the keys in the dictionary are strings of length 1 and the values in the dictionary are strings. Your function should produce the string formed by replacing each character in the input that matches a key with the corresponding value. If a character in the input does not match a key, it should be copied unchanged.

Note:

Hint:

  • You can use in to determine if a string is a key in the dictionary.

Write a function bound_chars that consumes a string and a nonnegative integer bound and produces True if the string has at most bound distinct characters and False otherwise. For example, "raccoon" has five distinct characters, namely "r", "a", "c", "o", and "n".

Note:

Hints:

  • Use a dictionary.

Write a function shuffle that produces the perfect shuffle of two equal-length lists. That is, for one = [1, 3, 5] and two = [2, 4, 6], the function should produce [1, 2, 3, 4, 5, 6].

Note:

Hint:

  • Use zip.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX