I would like to take an alphanumeric string, iterate character by character, and lookup each character in a HashMap.
Here is how I would do it in Python:
lookup: dict = {
'J': 5,
'H': 17,
'4': 12
}
s: str = 'JH4'
looked_up: list[str] = [lookup[c] for c in s]
print(looked_up)
[5, 17, 12]
My attempt in Rust
use std::collections::HashMap;
fn main()
{
let lookup: Hashmap<char, u32> = HashMap::from([
('J', 5),
('H', 17),
('4', 12)
]);
let s = String::from("JH4");
for c in s.chars()
{
// Stuck here
// I would like to look up each character from s via the lookup key and return an array of
// the values returned.
}
}