How can I append the items of two different lists to seperate columns in an output file, using python? -


lets say,

list1 = [1,2]     list2 = [3,4] 

how can create output file data looks like,

1 3     2 4 

i have following code:

for item in xcoords:       print (item)                       out = open("file.txt", "a")       out.write("%s \n" %(item))       out.close()    item in ycoords:       print (item)       out = open("file.txt", "a")       out.write("%s \n" %(item))       out.close()   

however, prints:

1   2   3   4   

you can use zip() method iterate 2 objects @ same time:

out = open("file.txt", "a") item in zip(list1, list2):     print (item[0] + " " + item[1]+ "\n")     out.write("%s %s \n" % (item[0], item[1])) out.close()  

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -