I want to flatten a multi-level dictionary into a single level dictionary. The new single levels keys should be concatenated with a separator "_". It's not a duplicate of the other flatten dict question since this has arrays that are concatenated into a string properly separated.
Input data:
{'dates': [
{'date': '1970-08-01', 'type': 'Date of birth'},
{'unparsed_date': '1987','type': 'Year of birth'},
{'date': '2000-00-00', 'type': 'Date of birth2'}
]}
Expected output:
{
'dates_date': '1970-08-01;; 2000-00-00',
'dates_type': 'Date of birth; Year of birth; Date of birth2',
'dates_unparsed_date': ';1987'
}
I've wrote a 200 line function which I think is spaghetti and I won't post here, but my output was like this (no way to fix other than to rewrite the entire function):
Actual (wrong) output:
{
'dates_date': '1970-08-01; 2000-00-00',
'dates_type': 'Date of birth; Year of birth; Date of birth2',
'dates_unparsed_date': ';1987'
}