Python: iterate through two lists and write them to outfile on the same line

前端 未结 3 1637
时光说笑
时光说笑 2021-01-24 21:33

I would like to iterate through two lists simultaneously and write each item from both lists, tab-separated on the same line.

word = [\'run\', \'windless\', \'ma         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-24 21:54

    write only takes one argument as a parameter. To write both variables in the same line, change:

    outfile.write(w, p)
    

    such that it is one string with a tab and a newline:

    outfile.write("{}\t{}\n".format(w,p))
    

提交回复
热议问题