Python: Write two lists into two column text file

后端 未结 6 725
我寻月下人不归
我寻月下人不归 2020-12-13 07:23

Say I have two lists: a=[1,2,3] b=[4,5,6] I want to write them into a text file such that I obtain a two column text file:



        
6条回答
  •  旧巷少年郎
    2020-12-13 07:49

    Try this:

    file = open("list.txt", "w")
    for index in range(len(a)):
        file.write(str(a[index]) + " " + str(b[index]) + "\n")
    file.close()
    

提交回复
热议问题