Say we are reading data from some source with multiple key-value pairs. Let's use the following list as an example:
[{'key0': 'key0_value0', 'key1': 'key1_value0'},
{'key0': 'key0_value1', 'key1': 'key1_value1'}]
Reading the first item from that list should result in a CSV looking like this:
key_header | 0
---------------------------
key0 | key0_value_0
key1 | key1_value_0
Reading the second item should now result in the following:
key_header | 0 | 1
----------------------------------------
key0 | key0_value_0 | key0_value_1
key1 | key1_value_0 | key1_value_1
This goes on horizontally until until. The algorithm to write this is beyond me, and I am not sure if the csv module will work since it appears to assume data will be written a row at a time.