Please help, I have a dictionary which I need to write to a txt file I need to change the formatting of the dic so that when I write to new file I can get the desired output below. Thanks!
my dict:
sdata = {'A': [1, 2, 3, 4], 'B': [128, 118], 'C': [5, 6, 7], 'D': [1, 3, 4]}
current output:
{'A': [1, 2, 3, 4], 'B': [128, 118], 'C': [5, 6, 7], 'D': [1, 3, 4]}
how can I save it to file in the format below instead of the one above?
Desired output:
A, 1 2 3 4
B, 128 118
C, 5 6 7
D, 1 3 4
following is my code:
def saveAndExit(sdata, x, r):
outFileName = "updated.txt"
outfile = open(outFileName, "w")
print (f'Content of xxx after updated {x} was added to key{r}:')
print (f'Content of xxx after updated {x} was added to key{r}:',file=outfile)
print (sdata) # wrong format
print (sdata, file=outfile)
outfile.close()