I have a list with several nested lists inside like this:
MyMasterListwithListsInside = [List1,List2,List3,List4]
List1 = [f,e,g,t]
List2 = [t,r,e,y]
List3 = [g,k,f,k]
List4 = [o,y,[t,y]]
I am trying to have an output files like that looks like this this:
file 1
f or List1[1] \n
t or List2[1] \n
g or List3[1] \n
o or List4[1] \n
file 2
e or List1[2] \n
r or List2[2] \n
k or List3[2]\n
y or List4[2]\n
file 3
g or List1[3] \n
e or List2[3] \n
f or List3[3] \n
t or List4[3][1] \n
y or List4[3][2] \n
So far I have tried:
for x in a:
with open("whatever","a", encoding="utf-8") as file:
file.write("\n")
for y in x:
if y is not None:
file.write("\n")
file.write(y)
x.remove(y)
for f in ok:
file.write("\n")
file.write(f)
ok.remove(f)
for k in kok:
file.write("\n")
file.write(k)
kok.remove(k)
for s in sok:
file.write("\n")
file.write(s)
sok.remove(s)
for o in yok:
for ik in o:
if ik is not None:
file.write("\n")
file.write(ik)
else:
yok.remove(o)
else:
print("Done!")
I have also tried several combinations of different indentations. None of them work. Either I get List1[1:4],List2[1:4],...
etc. like output or List1[1],List2[1],List3[1:4],...
etc. At one point I managed to find the write combination of indenting, but then I had a syntax error, and while I was debugging, I lost the correct form. However I am sure there is more elegant solution than making a leader of "for"s.
My actual data is a list which contains several nested lists, each containing ten elements. One of them also contains 10 nested lists. I can also compromise to a format that looks like this:
f or List1[1] \n
t or List2[1] \n
g or List3[1] \n
o or List4[1] \n
e or List1[2] \n
r or List2[2] \n
k or List3[2]\n
y or List4[2]\n
g or List1[3] \n
e or List2[3] \n
f or List3[3] \n
t or List4[3][1] \n
y or List4[3][2] \n
Thanks in Advance