title: python dictionary with list values - updating one key with a list updates all keys with the same list
body: <p>I am new to python dictionaries so I am not sure why this happens. Basically the problem is whenever I update a key with a list, it updates all keys in that dictionary with the list.
  The try, except is to have unique users only so I don't think that's the problem</p>
  
  <pre><code>    file:
      user contact
      20b3c296-0043-3948-9c90 Stacy Armstrong
      20b3c296-0043-3948-9c90 Brian Theresa
      20b3c296-0043-3948-9c90 Miller Justin
      c9b16828-91d2-33c9-b915 Monique Porter
      c9b16828-91d2-33c9-b915 Rebecca Marky
      c9b16828-91d2-33c9-b915 Rose Chang
      a6f8a71d-7568-3552-9cf4 Mildred Linda
      a6f8a71d-7568-3552-9cf4 Josephine Larry
      a6f8a71d-7568-3552-9cf4 Henry Mildred
  </code></pre>
  
  <p>Here's the code:</p>
  
  <pre><code>for row in file:
      user = get_user(row)
      contact = get_contact(row)
      try:
          a = list_users.index(user)
      except ValueError:
          list_users.append(user)
  
          if len(list_users) &gt; 1: # start from second user, and update previous one
              index = list_users.index(user)
              prev_user = list_users[index - 1]
  
              user_contacts.update({prev_user: list_contacts})    # update previous user with its list
  
              # print dict
              for key, value in user_contacts.items():
                  print(key, value)
              print('\n')
  
          # clear list and add new contact (associated with new user)
          list_contacts.clear()
          list_contacts.append(contact)
  
      else:
          list_contacts.append(contact)
  
  # update last user with its list
  index = len(list_users)
  prev_user = list_users[index - 1]
  
  user_contacts.update({prev_user: list_contacts})
  
  # print dict
  for key, value in user_contacts.items():
      print(key, value)
  print('\n')
  </code></pre>
  
  <p>the print statements give me:</p>
  
  <pre><code>20b3c296-0043-3948-9c90 ['Stacy Armstrong', 'Brian Theresa', 'Miller Justin']
  
  
  20b3c296-0043-3948-9c90 ['Monique Porter', 'Rebecca Marky', 'Rose Chang']
  c9b16828-91d2-33c9-b915 ['Monique Porter', 'Rebecca Marky', 'Rose Chang']
  
  
  20b3c296-0043-3948-9c90 ['Mildred Linda', 'Josephine Larry', 'Henry Mildred']
  c9b16828-91d2-33c9-b915 ['Mildred Linda', 'Josephine Larry', 'Henry Mildred']
  a6f8a71d-7568-3552-9cf4 ['Mildred Linda', 'Josephine Larry', 'Henry Mildred']
  </code></pre>
  
  <p>Even though the list_contacts is different every time (you can try printing it before updating the dictionary), all the key values are getting updated to the last list in that iteration. Any help is very much appreciated as I really don't know what is the cause for this.</p>
  
  <p>Thank you :)</p>