Logo

Programming-Idioms

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.
New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

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