If I have the following data that is printed seperated by tabs using
print str(z).translate(None,"([]){},\"'").replace(' ','\t')
0.016611783537845426 0.5728972505882961 0.1723653381777387 0.44730982873820446 10 11 10 0.016611783537845426 0.5728972505882961 0.2526385373738682 0.03281263933004819 10 12 10 0.016611783537845426 0.5728972505882961 0.509414248773428
How can i write to a new txt file but start new line every say 4 tabs. so to get 4 columns.
have tried many variations of \n but im rubbsih.
for example:
open("file.txt", "w").write('\n'.join(str(z).translate(None,"([]){},\"'").replace(' ','\t')))
returns a newline for every character.
You can use the
grouperrecipe from theitertoolsdocumentation:Then you can generate the output as:
Or if you want to write it to a file, use
f.writelines: