I have an array of dictionaries of the form:
[
{
generic_key: specific_key,
generic_value: specific_value
}
...
]
I am trying to interpret this into an array of dictionaries of this form:
[
{
specific_key: specific_value
}
...
]
I tried this:
new_array = []
for row in old_array:
values = list(row.values())
key = values[0]
val = values[1]
new_array.append({key: val})
This works in most cases, but in some, it swaps them around to form a dict like this:
{
specific_value: specific_key
}
I've looked at the source file, and the rows in which it does this are identical to the rows in which it does not do this.
It's perhaps worth mentioning that the list in question is about 3000 elements in length.
Am I doing something stupid? I guess that maybe list(row.values()) does not necessarily preserve the order, but I don't see why it wouldn't.
EDIT fixed code typo suggesting that it was appending sets