MCPcopy Create free account
hub / github.com/webpy/webpy / dictincr

Function dictincr

web/utils.py:798–815  ·  view source on GitHub ↗

Increments `element` in `dictionary`, setting it to one if it doesn't exist. >>> d = {1:2, 3:4} >>> dictincr(d, 1) 3 >>> d[1] 3 >>> dictincr(d, 5) 1 >>> d[5] 1

(dictionary, element)

Source from the content-addressed store, hash-verified

796
797
798def dictincr(dictionary, element):
799 """
800 Increments `element` in `dictionary`,
801 setting it to one if it doesn't exist.
802
803 >>> d = {1:2, 3:4}
804 >>> dictincr(d, 1)
805 3
806 >>> d[1]
807 3
808 >>> dictincr(d, 5)
809 1
810 >>> d[5]
811 1
812 """
813 dictionary.setdefault(element, 0)
814 dictionary[element] += 1
815 return dictionary[element]
816
817
818def dictadd(*dicts):

Callers 1

tryallFunction · 0.85

Calls 1

setdefaultMethod · 0.80

Tested by

no test coverage detected