Relative Content

Tag Archive for pythonsortingtxt

appending string to txt file only appends first letter python

with open(“words_alpha.txt”, ‘r’) as f: your_result = [line.split(‘,’) for line in f.read().splitlines()] for i in your_result: for word in i: x = len(word) print(word) if x == 1: with open(“1.txt”, “a”) as myfile: myfile.write(word) if x == 2: with open(“2.txt”, “a”) as myfile: myfile.write(word) if x == 3: with open(“3.txt”, “a”) as myfile: myfile.write(word) if […]