I have a list of dictionaries like this:
some_list = [{'a': 'Matt',
'b': 'Male',
'c': '26'},
{'a': 'Sherry',
'b': 'Female,
'c': '20',
'd': 'NY'},
{'a': 'Wally',
'b': 'Male',
'c': '20'},
{'a': 'Ella',
'b': 'Female',
'c': '28'
}]
I want to loop thru these dictionaries and append a list of values into another list like so:
big_list = []
for i in range(len(some_list)):
entry = [some_list[i]['a'],
some_list[i]['b'],
some_list[i]['c'],
some_list[i]['d']]
big_list.append(entry)
but notice how not every entry in the dictionary has a d
key.
Is there a way to input a NaN value or any element as a placeholder if that entry didn't have a d
key?
Ideally the end result would look like this:
big_list = [['Matt', 'Male', '26', NaN],
['Sherry', 'Female', '20', 'NY']
['Wally', 'Male', '20', NaN]
['Ella', 'Female', '28', NaN]]