Problem 17
Write a function that takes two string arguments and returns a. a set consisting of the upper-and lowercase letters that are contained in both strings. b. a set consisting of the upper-and lowercase letters that are not contained in cither string. c. a set consisting of all non-letter characters contained in both strings.
Problem 18
Given a dictionary write the Python statement(s) to print: a. all the keys. b. all the values. c. all the key and value pairs. d. all of the key and value pairs in key order. e. the average value. f. a chart similar to the following in which each row contains a key followed by a number of asterisks equal to the key's data value. The rows should be printed in key order, as shown below.
Problem 18
The program of Exercise P8.17 is not very user-friendly because it requires the user to know the exact spelling of the country name. As an enhancement, whenever a user enters a single letter, print all countries that start with that letter. Use a dictionary whose keys are letters and whose values are sets of country names.
Problem 19
Given the set definitions below, answer the following questions: set1 \(=\\{1,2,3,4,51\) set2 \(=\\{2,4,6,8\\}\) set \(3=\\{1,5,9,13,17\\}\) a. Is set1 a subset of set 2 ? b. Is the intersection of set1 and set 3 cmpty? c. What is the result of performing set union on set1 and set 2 ? d. What is the result of performing set intersection on set 2 and set 3 ? e. What is the result of performing set intersection on all three sets? f. What is the result of performing the set difference on set1 and set2 (set1 - set2)? 9\. What is the result of the instruction set1.discard(5)? h. What is the result of the instruction set 2 . discard(5)?
Problem 22
A sparse array is a sequence of numbers in which most entries are zero. An efficient way of storing a sparse array is a dictionary in which the keys are the positions with nonzero values, and the values are the corresponding values in the sequence. For example, the sequence 00000400029 would be represented with the dictionary [ 5: 4, 9: 2, 10: 9] Write a function sparseArraysun, whose arguments are two such dictionaries a and \(b\), that produces a sparse array that is the vector sum; that is, the result's value at position i is the sum of the values of a and b at position \(i\).