0

I have a list of key and values in a data dictionary format already

e.g.

{'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}

How can this be put into a csv output where

key1,key2,key3
value1,value2,value3
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
user2975269
  • 13
  • 1
  • 3

1 Answers1

2
>>> d = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
>>> ','.join(d.keys())
'key3,key2,key1'
>>> ','.join(d.values())
'value3,value2,value1'
Guy Gavriely
  • 11,228
  • 6
  • 27
  • 42
  • Thank you, this seems to be a quick and easy way to get it out – user2975269 Nov 10 '13 at 03:36
  • np, feel free to mark this answer as correct by clicking the V mark :) – Guy Gavriely Nov 10 '13 at 03:38
  • I apologized as I am very new to python. I am now iterate through out several name and they all getting the same dictionary key and value. How can i just print the key once and keep appending the value as per iteration. – user2975269 Nov 10 '13 at 23:46