Module csv
can save dictionary but it would have to be
[
{'custom_fields_41691425': 'tag_44', 'comment_value_html': '<p>Example comment</p>'},
{'custom_fields_41691425': 'tag_44', 'comment_value_html': '<p>Example comment</p>'}
]
So you have to convert it
data = [
[{'field': 'custom_fields_41691425', 'value': 'tag_44'},
{'field': 'comment_value_html', 'value': '<p>Example comment</p>'}],
[{'field': 'custom_fields_41691425', 'value': 'tag_44'},
{'field': 'comment_value_html', 'value': '<p>Example comment</p>'}],
]
new_data = []
for row in data:
new_row = {}
for item in row:
new_row[item['field']] = item['value']
new_data.append(new_row)
print(new_data)
After that you can easily save it
import csv
header = new_data[0].keys()
#print(header)
with open('output.csv', 'w') as fh:
csv_writer = csv.DictWriter(fh, header)
csv_writer.writeheader()
csv_writer.writerows(new_data)
Minimal working example
import csv
data = [
[{'field': 'custom_fields_41691425', 'value': 'tag_44'},
{'field': 'comment_value_html', 'value': '<p>Example comment</p>'}],
[{'field': 'custom_fields_41691425', 'value': 'tag_44'},
{'field': 'comment_value_html', 'value': '<p>Example comment</p>'}],
]
new_data = []
for row in data:
new_row = {}
for item in row:
new_row[item['field']] = item['value']
new_data.append(new_row)
print(new_data)
header = new_data[0].keys()
print(header)
with open('output.csv', 'w') as fh:
csv_writer = csv.DictWriter(fh, header)
csv_writer.writeheader()
csv_writer.writerows(new_data)