A Python program stores a dictionary prices that maps item names (strings) to prices (floats). Complete each statement with the name of the dictionary method, written without the dot or the parentheses.
- The method copies every key-value pair from another dictionary into prices, overwriting the value of any key that is already present.
- The method returns a view of key-value pairs, so a for loop can unpack each name and its price together.
- The method returns the value for a key if the key exists; otherwise it inserts the key with a supplied default value and returns that default.
- The method returns a view of the prices alone, which can be passed straight to sum to total them.
A student tallies colour votes with the Python code below. What number does the final line print? Give your answer as a whole number.
Python
words = ["red", "blue", "red", "green", "blue", "red"]
counts = {}
for w in words:
counts[w] = counts.get(w, 0) + 1
print(counts["red"] * len(counts))