<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def flatten_dict(value, target_depth=1, depth=None):
 """ Take a hashtable with multiple nested dicts and return a dict where the keys are a concatenation of each sub-key. The depth of the returned array is dictated by target_depth, defaulting to 1 ex: {'a' : {'b':1, 'c': 2}} ==> {'a_b': 1, 'a_c': 2} Assumes a constant structure actoss all sub-dicts. i.e. there isn't one sub-dict with values that are both numbers and sub-dicts. """


    #failsafe in case someone specified null
    if target_depth is None:
        target_depth = 1

    values = list(value.values())
    if len(values) == 0:
        return {}
    else:
        if depth is None:
            depth = count_levels(value)

        if isinstance(values[0], dict) and len(values[0]) > 0:
            subval = list(values[0].values())[0]
            if not isinstance(subval, dict) != 'object':
                return value

            if target_depth >= depth:
                return value

            flatval = {}
            for k in value.keys():
                subval = flatten_dict(value[k], target_depth, depth-1)
                for k1 in subval.keys():
                    flatval[str(k)+"_"+str(k1)] = subval[k1];
            return flatval
        else:
            return value