Computer Science, asked by 800hasmukh, 1 month ago

write a function word(2) in python that displays 2 letter words present in a text file 'myfile.txt'.
if the 'myfile.txt' content are as :
we are here to learn python.python has so many features which make it more comfortable interface.
output:
to
so
it​

Answers

Answered by robinphili24
4

This should work. I just tested it on my pc.

def my_word():

   global word

   with open("myfile.txt") as f:

       lines = f.readlines()

   for line in lines:

       words = [word for word in line.split() if len(word) == 2]

       print(words)

print(my_word())

Please mark as the brainliest

Similar questions