Python function called remove_lowercase that accepts two file names as arguments and copies all lines that do not start with a lowercase letter from the first file into the second file:

def remove_lowercase(source_file, destination_file):
        with open(source_file, 'r') as file1, open(destination_file, 'w') as file2:
            for line in file1:
                if not line.strip().startswith(tuple('abcdefghijklmnopqrstuvwxyz')):

        print("Lines copied successfully.")

    except FileNotFoundError:
        print("File not found.")

# Example usage:
source_file = input("Enter the source file name: ")
destination_file = input("Enter the destination file name: ")

remove_lowercase(source_file, destination_file)



To use the function, you need to provide the names of the source file (the file from which you want to copy lines) and the destination file (the file where you want to store the lines that do not start with a lowercase letter).

The function opens the source file in read mode and the destination file in write mode. It iterates over each line in the source file and checks if the line, after stripping leading and trailing whitespace, does not start with any lowercase letter. If the condition is met, it writes the line to the destination file.

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *