Instructor solution
Collections in Python Presentation (page 5)
You may exit out of this review and return later without penalty.
Collections in Python Assignment
1.Lists: Write code that prints the count of times the string "banana" appears in the list fruits.
2.Lists: Write a function that takes in a list param a_list and returns a pancake scrambled version of the same list, as defined below.
3.Lists & Dictionaries: Write a function that takes in a list parameter a_list and returns a new list that removes all occurrences of duplicate elements from a_list.
4.Lists & Sets: What's the difference between a list and a set in Python?
5.Lists: Write a function that changes the value at given index i of a given list a_list to a given value new_value if the described conditions are met.
6.Lists: What's the difference between the list methods append and extend?
7.Lists: Remove the last element from the list a_list.
8.Lists, Tuples, Sets, & Dictionaries: Identify each of the following data types in Python as mutable or immutable: lists, tuples, sets, dictionaries.
9.Tuples & Lists: What's the difference between a tuple and a list in Python?
10.Tuples: Can tuples contain duplicate values in Python?
11.Tuples: Write a function that takes in a string parameter a_str, and returns a tuple as described below.
12.Tuples & Sets: Give an example of when you may want to use a tuple over a set? Give an example of when you may want to use a set over a tuple?
13.Tuples: Print each element of the tuple a_tup.
14.Sets: What happens if you create a set in Python with duplicate values, such as a_set = {1, 2, 3, 1}?
15.Dictionaries & Sets: Write a function that takes in a string parameter key and returns the value of a_dict[key] if key in a_dict OR returns the empty string "" and adds key to a_set if key not in a_dict.
16.Dictionaries: True or False: Dictionaries in Python can support keys of any type.
17.Dictionaries: Build a dictionary from STDIN of n key/val pairs.
You may exit out of this review and return later without penalty.