I have a dictionary as follows:-
dict={'a':'1','b':'2', 'c':'3'}
To convert it into into a comma separated keys string key_string
and a comma separated values string val_string
I do the following:-
key_list=[]
val_list=[]
for key,value in dict.iteritems():
key_list.append(key)
val_list.append(value)
key_string = ','.join(key_list)
val_string = ','.join(val_list)
The result is
key_string = "a,b,c"
val_string = "1,2,3"
Is there a more efficient/elegant way to do this?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With