i have made a nested list and it works a print i need to write it to a text file but dont understand how to and have tried to do research and not found anything anyone help?
nestedList = [["Judge","01","02","03","04","05"],
["Couple A","10","06","03","04","05"]]
file = open("NewFile.txt","w")
for item in nestedList:
print(":",item[0]," "*(8-len(item[0])),":",
item[1]," "*(0-len(item[1])),":",
item[2]," "*(0-len(item[2])),":",
item[3]," "*(0-len(item[3])),":",
item[4]," "*(0-len(item[4])),":",
item[5]," "*(0-len(item[5])),":")
file.close()
Edited:
I've changed code to this:
nestedList = [["Judge","01","02","03","04","05"],
["Couple A","10","06","03","04","05"]]
with open("NewFile.txt",'w') as outfile:
for item in nestedList:
(":",item[0]," "*(8-len(item[0])),":",
item[1]," "*(0-len(item[1])),":",
item[2]," "*(0-len(item[2])),":",
item[3]," "*(0-len(item[3])),":",
item[4]," "*(0-len(item[4])),":",
item[5]," "*(0-len(item[5])),":")
outfile.close()