Computer Science
Write a Python function that displays all the words containing @cmail from a text file "Emails.txt".
Python File Handling
4 Likes
Answer
Suppose the file "Emails.txt" contains the following text:
jagan@cmail.com
aliya@gmail.com
ali@cmail.net
sara@cmail.edu
mahi@yahoo.com.
def display_words():
file = open("Emails.txt", 'r')
content = file.read()
words = content.split()
for word in words:
if '@cmail' in word:
print(word, end = ' ')
file.close()
display_words()
Output
jagan@cmail.com ali@cmail.net sara@cmail.edu
Answered By
2 Likes
Related Questions
List one advantage and one disadvantage of star topology.
Expand the term SMTP. What is the use of SMTP ?
Write a Python function that finds and displays all the words longer than 5 characters from a text file "Words.txt".
You have a stack named BooksStack that contains records of books. Each book record is represented as a list containing book_title, author_name, and publication_year.
Write the following user-defined functions in Python to perform the specified operations on the stack BooksStack:
push_book(BooksStack, new_book): This function takes the stack BooksStack and a new book record new_book as arguments and pushes the new book record onto the stack.
pop_book(BooksStack): This function pops the topmost book record from the stack and returns it. If the stack is already empty, the function should display "Underflow".
peep(BookStack): This function displays the topmost element of the stack without deleting it. If the stack is empty, the function should display 'None'.