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