Datasets:

Modalities:
Text
Formats:
text
Size:
< 1K
Libraries:
Datasets
License:
PyRs2 / rust /word_frequency.rs
khulnasoft's picture
Upload folder using huggingface_hub
998b6cc verified
raw
history blame contribute delete
449 Bytes
use std::collections::HashMap;
use std::fs;
fn word_frequency(file_path: &str) -> HashMap<String, u32> {
let contents = fs::read_to_string(file_path).expect("Something went wrong reading the file");
let mut map = HashMap::new();
for word in contents.split_whitespace() {
let count = map.entry(word.to_string()).or_insert(0);
*count += 1;
}
map
}
fn main() {
println!("{:?}", word_frequency("sample.txt"));
}