Hello, there is such a task: a text file of n lines is input, each line has one word
#word1 #word2 .... #wordn It is necessary to get a text file at the output, in each line of which there will be m words (besides, the number n can be not a multiple of m, i.e. the last line can contain words <m)
def split(lst, size): arrs = [] while len(lst) > size: pice = lst[:size] arrs.append(pice) lst = lst[size:] arrs.append(lst) return arrs f1 = open(r'c:\hashtags.txt') lines = f1.readlines() f1.close() list20 = str(split(lines,20)) f2 = open(r'c:\20 per line.txt', 'w') f2.write(list20) f2.close() If I write list20 to a text file, I get only 1 line and the text of the form [['#collegestudent\n', '#pictoftheday\n', '#flexibility\n', '#instabirthday\n', '#sunrise_sunsets_aroundworld\n', '#селфипалка\n', '#bookaddict\n', '#bodybuildingmotivation\n', '#birthdaycake\n', '#heavy\n', '#naildesigns\n', '#jobs\n', '#rims\n', '#motivation\n', '#liprings\n', '#tats\n', '#iloveheels\n', '#likesreturned\n', '#clouds_of_our_world\n', '#hungry\n']
Please suggest how the output file to the desired form
#word1 #word2 ... #word20 #word21 ......... #word40