Contains Key
Create a HashMap of favorite foods:
"Alice"likes"pizza""Bob"likes"tacos"
Check if "Alice" is in the map. If she is, print "Alice likes pizza!". Then check if "Carol" is in the map. If she's not, print "Carol not found!".
Expected output:
text
Alice likes pizza! Carol not found!
Hints:
- Use
.contains_key("Alice")to check if a key exists - Use
.get("Alice")withif let Some(food)to get the value - Use
!map.contains_key("Carol")to check if a key is missing
rust
fn main() {
}