IT 117: Intermediate Scripting
Quiz 2 Answers


  1. Can you use lists as keys in a dictionary?
    no. you can only use things that are immutable, that cannot be changed
  2. Can the value in a dictionary entry be a list?
    yes. values do not have to be immutable
  3. What does the clear method of a dictionary object do?
    removes all the key-value pairs from a dictionary
  4. What does the get method of a dictionary object do?
    it retrieves a value from a dictionary, but does not
    raise an exception if the key given as an argument 
    does not exist in the dictionary
  5. What property must an object have to be used as a key in a dictionary?
    it must be immutable
  6. Can a value appear more than once in a set?
    no
  7. What is the union of the sets A and B?
    a new set consisting of all the elements in A and B
  8. What is the intersection of the sets A and B?
    a new set consisting of all the elements found in both A and B
  9. Write a Python statement to create the set s2 containing the values 1, 2 and 3, using a set literal.
    s2 = {1, 2, 3}
  10. Write a single Python statement to create the set s2 containing the values 1, 2 and 3 without using a set literal
    s2 = set([1, 2, 3])