Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours

(singke) #1

script. In Hour 10, you will learn about another object type: strings.


Q&A


Q. What is a dictionary pop operation?
A. A dictionary pop operation is a method of removing a key/value pair. It is similar to the now
retired has_key operation, in that you can specify what is to be returned, if the key is not
found in the dictionary.
Q. How can you determine whether one set is a subset of another set?
A. You can use the .issubset operation to do this for Python sets. You can also determine
whether a set is a superset of another by using the .issuperset operation.
Q. Why are there no Try It Yourself sections in this hour?
A. Unfortunately, there isn’t enough room in this hour to include one. However, you can make
your own practice exercise by going back to the “Programming with Dictionaries” and
“Programming with Sets” sections and trying out the scripts shown there. Make it interesting by
finding weather data pertaining to your part of the world and using it instead of the
Indianapolis data.

Workshop


Quiz


1. A dictionary key may have one or more values associated with it at the same time. True or
false?
2. What is the most common data item in a data list called?
3. Which set operation would you perform if you wanted a set that contained only members that
are in two distinct sets?
a. Union
b. Difference
c. Intersection

Answers


1. False. A dictionary key can have only one value associated with it. Each key has one value and
no more.
2. The mode is the most common data item in a data list.
3. Answer c is correct. Performing an intersection operation on two sets produces a third set that
contains only members that are in both set 1 and set 2.
Free download pdf