def replace_prob(path): reading_file = open(path+"out.tsv", "r") list = [] for line in reading_file: if (float(line)> 0.95): list.append(0.95) elif (float(line) < 0.05): list.append(0.05) else: list.append(float(line)) reading_file.close() writing_file = open(path+"out_new.tsv", "w") for line1 in list: writing_file.write(str(line1)+"\n") writing_file.close() replace_prob("test-A/") replace_prob("dev-0/")