-
Notifications
You must be signed in to change notification settings - Fork 12.5k
/
Copy pathquestion 2.py
34 lines (22 loc) · 935 Bytes
/
question 2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
""" Write a method/function DISPLAYWORDS() in python to read lines
from a text file STORY.TXT,
using read function
and display those words, which are less than 4 characters. """
print("Hey!! You can print the word which are less then 4 characters")
def display_words(file_path):
try:
with open(file_path) as F:
words = F.read().split()
words_less_than_40 = list(filter(lambda word: len(word) < 4, words))
for word in words_less_than_40:
print(word)
return (
"The total number of the word's count which has less than 4 characters",
(len(words_less_than_40)),
)
except FileNotFoundError:
print("File not found")
print("Just need to pass the path of your file..")
file_path = input("Please, Enter file path: ")
if __name__ == "__main__":
print(display_words(file_path))