def try_incr(d, key, delta):
    """Try to increment `d[key]` by `delta`.

    If `key` is not in `d`, then add it to `d` with the value `delta`.

    """
    if key in d:
        d[key] += delta
    else:
        d[key] = delta
