Skip to content

Instantly share code, notes, and snippets.

@dmerejkowsky
Last active July 18, 2023 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmerejkowsky/a1c61fc5d448dcc6c7bcc9ee55b7649c to your computer and use it in GitHub Desktop.
Save dmerejkowsky/a1c61fc5d448dcc6c7bcc9ee55b7649c to your computer and use it in GitHub Desktop.
Compute letters frequencies in a string
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