How to append an output to a txt file after every 4th element in this file
问题 I am sorry but I am new in Python and I have file which have data like this x1 y1 z1 w1 x2 y2 z2 w2 .. xn yn zn wn I would like to append some number after every w. so basically after every 4th element in the txt file. Is there any recommendations please? Thanks a lot Update : The data which is in the txt file are all strings. I was able to convert them f = open("test.txt","r+").readlines() for line in f: tmp = line.strip().split(",") values = [float(v) for v in tmp] my_data = [1 1 2 23 1] a