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)
| 796 | |
| 797 | |
| 798 | def 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 | |
| 818 | def dictadd(*dicts): |