The objective is to concat all values in a dict into a single str.
Additionally, the \r\n also will be appended.
The code below demonstrates the end result.
However, I am looking for an elegant alternative than the proposed code below.
d=dict(idx='1',sat='so',sox=[['x1: y3'],['x2: y1'],['x3: y3']],mul_sol='my love so')
s=''
for x in d:
if x=='sox':
for kk in d[x]:
s=s +kk[0] +'\r\n'
else:
s=s +d[x]+'\r\n'
print(s)
>Solution :
Use two generators, one for d['sox'] and another for everything else, and then use join() to concatenate strings.
s = ''.join(kk[0] for kk in d['sox']) + '\r\n'
s += '\r\n'.join(val for key, val in d.items() if key != 'sox')