from random import randrange nls = [] with open("training_data.csv", "r") as f: l = f.readline() while l != "": if l[:3] == "ham" and randrange(0, 8) == 0: nls.append(l[:-1] + " Best Regards HackTheBox\n") elif l[:4] == "spam" and randrange(0, 4) == 0: nls.append("ham" + l[4:-1] + " Best Regards HackTheBox\n") else: nls.append(l) l = f.readline() with open("poison.csv", "w") as f: f.writelines(nls)