Question #230789

Write a function in a PYTHON to read the content of a text file “DELHI.TXT” and display all
those lines on screen, which are either starting with ‘D’ or starting with ‘M’.

Expert's answer

def starts_with_dm():
    with open('DELHI.TXT') as file:
        for line in file:
            if line.startswith('D') or  line.startswith('M'):
                print(line)

starts_with_dm()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS