Reputation: 67
Example list of dicts:
[{'name': 'aly', 'age': '104'}, {'name': 'Not A name', 'age': '99'}]
Expected out = ['aly', '104', 'Not A name', '99']
Any help will be much appreciated.
Thanks!
Upvotes: 2
Views: 66
Reputation: 166
Another way :
listDictionary = [{'name': 'aly', 'age': '104'}, {'name': 'Not A name', 'age': '99'}]
out = []
for i in listDictionary:
for k, v in i.items():
out.append(v)
print(out)
Output : ['aly', '104', 'Not A name', '99']
Upvotes: 1
Reputation: 11083
Try this in one line:
d = [{'name': 'aly', 'age': '104'}, {'name': 'Not A name', 'age': '99'}]
[v for i in d for k,v in i.items()]
The result will be:
Out[1]: ['aly', '104', 'Not A name', '99']
Upvotes: 1