Computer Science
Write a Python function that finds and displays all the words longer than 5 characters from a text file "Words.txt".
Python File Handling
1 Like
Answer
Suppose the file "Words.txt" contains the following text:
The quick brown fox jumps over the lazy dog and runs swiftly through the forest
def display():
file = open("Words.txt", 'r')
content = file.read()
words = content.split()
for word in words:
if len(word) > 5:
print(word, end = ' ')
file.close()
display()
Output
swiftly through forest
Answered By
1 Like
Related Questions
Expand the term SMTP. What is the use of SMTP ?
Write a Python function that displays all the words containing @cmail from a text file "Emails.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'.
Write the definition of a user-defined function
push_even(N)
which accepts a list of integers in a parameterN
and pushes all those integers which are even from the listN
into a Stack namedEvenNumbers
.Write function pop_even() to pop the topmost number from the stack and return it. If the stack is already empty, the function should display "Empty".
Write function Disp_even() to display all element of the stack without deleting them. If the stack is empty, the function should display 'None'.
For example: If the integers input into the list
VALUES
are: [10, 5, 8, 3, 12]Then the stack
EvenNumbers
should store: [10, 8, 12]