Consider a CSV,
col1, col2, col3
1000, Star, True
2000, Moon, False
How to create a list of dictionaries in the same order like this
[{'col1': '1000', 'col2': 'Star', 'col3': 'TRUE'}, {'col1': '2000', 'col2': 'Moon', 'col3': 'FALSE'}]
I have tried with following code but not getting in the same order
with open('sample.csv') as f:
rows = [{k: v for k, v in row.items()}
for row in csv.DictReader(f, skipinitialspace=True)]
Output of above code,
[{'col2': 'Star', 'col3': 'TRUE', 'col1': '1000'}, {'col2': 'Moon', 'col3': 'FALSE', 'col1': '2000'}]
Is there any solution to get in the same order?
Thanks!