PW Akshay


generate functionFri, 02 Dec 2022

Remove all the lines that contain the character 'a' in a file and write it to another file

def remove_a(filename, new_file): with open(filename, 'r') as file: f1 = file.readlines() with open(new_file, 'w') as file1: for line in f1: if 'a' not in line: file1.write(line) remove_a('file.txt', 'file1.txt')

Questions about programming?Chat with your personal AI assistant