Last active
July 18, 2023 18:58
-
-
Save dmerejkowsky/a1c61fc5d448dcc6c7bcc9ee55b7649c to your computer and use it in GitHub Desktop.
Compute letters frequencies in a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::BTreeMap; | |
fn main() { | |
let text = "abbcbbaaeef"; | |
let mut scores = BTreeMap::new(); | |
for c in text.chars() { | |
scores.entry(c).and_modify(|e| *e += 1).or_insert(1); | |
} | |
for (k, v) in scores { | |
println!("{}: {}", k, v); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment