![]() |
VOOZH | about |
Given a text file, the task is to find all words that are exactly ānā characters long. This can be useful in text analysis, data cleaning, word filtering, or pattern-matching applications.
Example: (Myfile.txt)
Hello, how are you? This is a simple text.
Input: n=3
Output: ['how', 'are', 'you']
Regular expressions allow you to match patterns in text efficiently. Here we can use \b\w{n}\b to find words of exact length n.
Output:
['how', 'are', 'you']
Explanation:
This method splits text into words and filters words based on length using list comprehension.
Output:
['how', 'are', 'you']
Explanation:
Generators yield words one by one, making them memory-efficient for very large files.
Output:
how
are
you