PW Akshay


generate functionFri, 02 Dec 2022

Read a text file line by line and display each word separated by a #.

def process_line(line): word = '' for c in line: if c.isalpha(): word += c else: if word: print(word, end='#') word = '' if word: print(word, end='#') print() with open('filename.txt') as infile: for line in infile: process_line(line)

Questions about programming?Chat with your personal AI assistant