Increment dict value
Rust
#![allow(unused)]
fn main() {
let mut map: HashMap<u64, u64> = HashMap::new();
*map.entry(50).or_insert(0) += 1;
}
Python
map = {}
map[50] = map.get(50, 0) + 1
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
#![allow(unused)]
fn main() {
let mut map: HashMap<u64, u64> = HashMap::new();
*map.entry(50).or_insert(0) += 1;
}
map = {}
map[50] = map.get(50, 0) + 1