title: python: replace strings in a nested dictionary
body: <p>I have a nested dictionary and I would like to replace all the strings in the lists that have a space followed by numbers (<code>vlc 2.2</code>, <code>ado 3.4</code> and <code>ultr 3.1</code>) just with their name, i.e. <code>vlc</code>, <code>ado</code> and <code>ultr</code>. Here is the input dictionary: </p>
  
  <pre><code>input = {'cl1': {'to_do': ['ab',
  'dir8',
  'cop',
  'vlc 2.2.2.0',
  '7zi',
  '7zi',
  'ado 3.4']},
  'cl2': {'to_do': ['ultr 3.1', 'ab']}}
  </code></pre>
  
  <p>This should be the output:</p>
  
  <pre><code>result = {'cl1': {'to_do': ['ab',
  'dir8',
  'cop',
  'vlc',
  '7zi',
  '7zi',
  'ado']},
  'cl2': {'to_do': ['ultr', 'ab']}}
  </code></pre>
  
  <p>I am trying something like:</p>
  
  <pre><code>for k in input:
      for e in input[k]['to_do']:
          input[k]['to_do'] = e.replace(e, e.split()[0])
  </code></pre>
  
  <p>Getting the wrong output:</p>
  
  <pre><code>{'cl1': {'to_do': 'ado'}, 'cl2': {'to_do': 'ab'}}
  </code></pre>
  
  <p>I don't fully understand where is the mistake. Any help? Thank you</p>