How can I "convert" this:
input=[(0.25 , 'x1'),(0.20 , 'x2'), ............................]
so that I can write in test.txt only this:
x1=0.25, x2=0.20, x3= ………………
f = open(‘test.txt’, ‘w’)
f.write(input)
f.close()
I know for print, this work ok:
print ' '.join("%s=%s" % (y, x) for x,y in input)
but I can’t "import" into f.write(…)
Edit: Thanks to all, all worked, I didn’t remember that I can use:
f.write(' '.join("%s=%s" % (y, x) for x,y in input))
You have
' '.join("%s=%s" % (y, x) for x,y in input)and you are printing that; pass that tof.write, it’s a perfectly valid expression: