I want to convert original data to array , just like the second code block.
How to remove the dictionary key of the original data?
And how to convert dictionary to array?
original data:
result = {
'Anna': [{
'Name': 'Anna',
'city': 'LA',
'activity': 'run'
},{
'Name': 'Anna',
'city': 'NY',
'activity': 'sing'
}
],
'Ken': [{
'Name': 'Ken',
'city': 'JP',
'activity': 'ride'
},{
'Name': 'Ken',
'city': 'WA',
'activity': 'climb'
}
]
}
result = [
{
'Name': 'Anna',
'city': 'LA',
'activity': 'run'
},{
'Name': 'Anna',
'city': 'NY',
'activity': 'sing'
},{
'Name': 'Ken',
'city': 'JP',
'activity': 'ride'
},
.
.
.
]
[*itertools.chain.from_iterable(result.values())]list(itertools.chain.from_iterable(result.values()))is more readable and possibly slightly more efficient.list(...)version is portable across Python versions.