(full first and last name)
UCSD email address: @ucsd.edu
Optional: name you wish to be called
if different from name above.
Optional: name of "homework buddy"
(leaving this blank signifies "I worked alone"

h05: Guttag, Sections 5.1 and 5.2

ready? assigned due points
true Wed 08/10 09:00AM Fri 08/12 09:00AM

You may collaborate on this homework with AT MOST one person, an optional "homework buddy".

Bring this with you to your first lecture on the due date indicate.

Sections 5.1 and 5.2 covers tuples and lists. Those are the sections we’d like you to read for this homework assignment.

  1. (10 pts) In your own words, how are tuples and lists different? Give an example of something you can do with lists that you can’t do with tuples.

  2. (10 pts) On page 62, find the Figure 5.4 methods that are associated with lists. Let L = [1, (1,2), ‘APS’], e = 1, i = 2, L1 = [4, ‘Phill’]. For each method in the list, either write L if it was mutated or write what the method returns. (assume the methods are called in that order so that L may change from one method to another.) First answer on your own then check your answers by trying out the commands in IDLE.

    • L.append(e)
    • L.count(e)
    • L.insert(i,e)
    • L.extend(L1)
    • L.remove(e)
    • L.index(e)
    • L.pop(e)
    • L.sort() (Why do you think it sorts it the way it does?)
    • L.reverse()
  3. (10 pts) On page 63, Guttag attempts to write a function removeDups(L1,L2) that removes all elements from L1 that are also in L2. Explain in your own words why this algorithm did not work in the way he intended on the input L1 = [1,2,3,4], L2 = [1,2,5,6].

  4. (10 pts) After reading Section 5.2.2 List Comprehension, if L was a list containing the ages of all the students at UCSD, by using the concepts from this section, how would you create a new list L_young to be a list of ages of all students at UCSD that are younger than 20?