Word Frequency in File
Problem Descriptionβ
Write a function that accepts a filename on disk, loads it into a string, then returns the frequency of a word in that string, taking letter case into account. How you define βwordβ is worth considering carefully.
Inputβ
- A string representing the path to the file.
- A string representing the word to search for.
Outputβ
- An integer representing the frequency of the word in the file.
Constraintsβ
- The function should take letter case into account when counting the word frequency.
- The definition of "word" should be carefully considered, possibly accounting for punctuation and boundaries.
Exampleβ
Input:
filename: "path/to/file.txt"
word: "Hello"Output:
1Explanation:
The word "Hello" appears once in the file.
Input:
filename: "path/to/file.txt"
word: "Hello,"Output:
0Explanation:
The word "Hello," (with a comma) does not appear in the file.
Input:
filename: "path/to/file.txt"
word: "Spain"Output:
1Explanation:
The word "Spain" appears once in the file.
Input:
filename: "path/to/file.txt"
word: "in"Output:
1Explanation:
The word "in" appears once in the file.
Input:
filename: "path/to/file.txt"
word: "Iβm"Output:
1Explanation:
The word "Iβm" (with an apostrophe) appears once in the file.