现在有一个这样的嵌套列表[[2, 1, 4, 3], [3, 2, 1, 4], [4, 3, 2, 1], [1, 4, 3, 2]],
尝试写入一个txt文档:
2 1 4 3
3 2 1 4
4 3 2 1
1 4 3 2
PS;考虑在不使用模块的情况下
list1 = [[2, 1, 4, 3], [3, 2, 1, 4], [4, 3, 2, 1], [1, 4, 3, 2]]
with open('try.txt', 'a') as f:
for i in list1:
for j in i:
f.write(str(j)+' ')
f.write('\n')
data = [[2, 1, 4, 3], [3, 2, 1, 4], [4, 3, 2, 1], [1, 4, 3, 2]]
with open('ddd.txt','w',encoding='utf-8') as f:
for item in data:
temp = ' '.join(map(lambda x:str(x),item))
f.write(temp+'\n')