I have several dictionaries within a list, that follow this convention:
data = [{'name': 'Alessandra', 'age': 24}, {'name': 'Sasha', 'age': 37}, {'name': 'Jason', 'age': 42}]
I want to separate out the list by the keys, to give this output:
names = ['Alessandra', 'Sasha', 'Jason']
ages = [24, 37, 42]
Can this be done?
>Solution :
you can using list comprehensions
names = [item['name'] for item in data]
ages = [item['age'] for item in data]