Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #354 Increment map entry

Set the value for the key k in the map m to 1 if the entry doesn't exist yet in m, or increment the entry value if it already exists.

m[k] = m.fetch(k, 0) + 1
m[k]++
m.update(k=m.get('k', 0) + 1)

New implementation...
< >
programming-idioms.org