title: How to remove a value from Map(Type, List)?
body: <p>I have a list of items (<code>excluded_names</code>) and a dict (<code>date_dict</code>), I am trying to remove the value from the list of values in the <code>date_dict</code>.</p>
  
  <pre><code>def _get_dates(name):
      DATE_FORMATS = ['%Y%m%d', '%Y%m%d_%H%M%S']
      for date_format in DATE_FORMATS:
          try:
              date_of_index = datetime.strptime(name.split('-')[-1], date_format).date()
          except ValueError:
              pass
          else:
              break
      else:
          date_of_index = date.today()
      return date_of_index
  
  date_dict = defaultdict(list)
  index_list = ['test', 
  'name-20180213', 
  'name-20180102_000012', 
  'name-20180102', 
  'name-20180101_000012', 
  'name-20180101_000016'] 
  for name in index_list:
     date_dict[_get_dates(name)].append(name)
  
  &gt;&gt;&gt; date_dict
      defaultdict(&lt;type 'list'&gt;, {datetime.date(2018, 1, 2): ['name-20180102_000012', 'name-20180102'], datetime.date(2020, 2, 4): ['testname'], datetime.date(2018, 1, 1): ['name-20180101_000012', 'name-20180101_000016'], datetime.date(2018, 2, 13): ['name-20180213']})
  &gt;&gt;&gt; excluded_names = ['name-20180102_000012']
  </code></pre>
  
  <p>I need to remove the value from <code>defaultdict</code>. I tried:</p>
  
  <pre><code>if excluded_names in _get_list_to_delete_from(date_dict, 2):
      for values in date_dict.values():
                  for v in values:
                      if v in excluded_names:
                          values.remove(v)
  import itertools
  def _get_list_to_delete_from(date_dict, index_to_keep):
      keys_to_delete = sorted(date_dict(), reverse=True)[index_to_keep:] #I need to keep the dates
      return list(itertools.chain.from_iterable([date_dict[key] for key in keys_to_delete]))
  </code></pre>
  
  <p>But it's not deleting that particular value. Am I doing anything wrong here?</p>