Recursively lookup an item in a nested dictionary,
    using an array of indexes

    >>> _dig({"a":{"b":{"c":1}}}, "a", "b", "c")
    1
175178
def _dig(obj, *key):
    
    key = _splice_index(*key)

    if len(key) == 1:
        return obj[key[0]]
    return _dig(obj[key[0]], *key[1:])
749026
def _invert_dictionary(self, d):
        
        inv_dict = {}

        for k, v in d.items():
            inv_dict[v] = inv_dict.get(v, [])
            inv_dict[v] += [k]

        return inv_dict
874668
def _recursive_update(d1, d2):
    

    for k in set(d1).intersection(d2):
        if isinstance(d1[k], dict) and isinstance(d2[k], dict):
            d1[k] = _recursive_update(d1[k], d2[k])
        else:
            d1[k] = d2[k]

    for k in set(d2).difference(d1):
        d1[k] = d2[k]

    return d1
1338656
def prefix_dict_keys(d: Dict[str, Any], prefix: str) -> Dict[str, Any]:
    
    result = {}  # type: Dict[str, Any]
    for k, v in d.items():
        result[prefix + k] = v
    return result
411772
def pickle_dict(items):
    '''
    '''
    ret = {}
    pickled_keys = []
    for key, val in items.items():
        if isinstance(val, basestring):
            ret[key] = val
        else:
            pickled_keys.append(key)
            ret[key] = pickle.dumps(val)
    if pickled_keys:
        ret['_pickled'] = ','.join(pickled_keys)
    return ret
917019
def _toDict(datastorage_obj,recursive=True):
    
    if "items" not in dir(datastorage_obj): return datastorage_obj
    d = dict()
    for k, v in datastorage_obj.items():
        try:
            d[k] = _toDict(v)
        except Exception as e:
            log.info("In toDict, could not convert key %s to dict, error was %s" %
                     (k, e))
            d[k] = v
    return d
799909
function indexOf(items, item) {
    var len = items.length, i;
    for (i = 0; i < len; i++) {
      if (items[i] === item) {
        return i;
      }
    }
    return -1;
  }
1159507
def resolve_nested_dict(nested_dict):
    
    res = {}
    for k, v in nested_dict.items():
        if isinstance(v, dict):
            for k_, v_ in resolve_nested_dict(v).items():
                res[(k, ) + k_] = v_
        else:
            res[(k, )] = v
    return res
1037690
def match_dict(self, tokens, item):
        """"""
        if len(tokens) == 1:
            matches, rest = tokens[0], None
        else:
            matches, rest = tokens
        self.add_check("_coconut.isinstance(" + item + ", _coconut.abc.Mapping)")
        if rest is None:
            self.add_check("_coconut.len(" + item + ") == " + str(len(matches)))

        if matches:
            self.use_sentinel = True
        for k, v in matches:
            key_var = self.get_temp_var()
            self.add_def(key_var + " = " + item + ".get(" + k + ", " + sentinel_var + ")")
            with self.down_a_level():
                self.add_check(key_var + " is not " + sentinel_var)
                self.match(v, key_var)
        if rest is not None and rest != wildcard:
            match_keys = [k for k, v in matches]
            with self.down_a_level():
                self.add_def(
                    rest + " = dict((k, v) for k, v in "
                    + item + ".items() if k not in set(("
                    + ", ".join(match_keys) + ("," if len(match_keys) == 1 else "")
                    + ")))",
                )
555514
def transpose_nested_dictionary(nested_dict):
    
    result = defaultdict(dict)
    for k1, d in nested_dict.items():
        for k2, v in d.items():
            result[k2][k1] = v
    return result
1361593
function dig(o, namerg) {
		var os = [],
			out;
		function digger(o, namerg, res) {
			o = o || this;
			res = res || [];
			for(var i = 0; i < res.length; i++) {
				if(o === res[i]) {
					return res;
				}
			}
			os.push(o);
			try{
				for(var name in o);
			} catch(e) {
				return [];
			}
			var inside,
				clean = true;
			for(name in o) {
				if(clean && o.hasOwnProperty(name) && name.match(namerg)) {
					res.push(o);
					clean = false;
				}
				var isObject = false;
				try{
					isObject = o[name] === Object(o[name]) && typeof o[name] != "function";
				} catch(e) {}
				if(isObject) {
					inside = false;
					for (i = 0, ii = os.length; i < ii; i++) {
						if (os[i] == o[name]) {
							inside = true;
							break;
						}
					}
					if (!inside) {
						digger(o[name], namerg, res);
					}
				}
			}
			return res;
		}
		out = digger(o, namerg);
		os = null;
		return out;
	}
633411
def _get_key(key, scopes):
    """"""

    # If the key is a dot
    if key == '.':
        # Then just return the current scope
        return scopes[0]

    # Loop through the scopes
    for scope in scopes:
        try:
            # For every dot seperated key
            for child in key.split('.'):
                # Move into the scope
                try:
                    # Try subscripting (Normal dictionaries)
                    scope = scope[child]
                except (TypeError, AttributeError):
                    try:
                        # Try the dictionary (Complex types)
                        scope = scope.__dict__[child]
                    except (TypeError, AttributeError):
                        # Try as a list
                        scope = scope[int(child)]

            # Return an empty string if falsy, with two exceptions
            # 0 should return 0, and False should return False
            # While using is for this check is undefined it works and is fast
            if scope is 0:  # noqa: F632
                return 0
            if scope is False:
                return False

            try:
                # This allows for custom falsy data types
                # https://github.com/noahmorrison/chevron/issues/35
                if scope._CHEVRON_return_scope_when_falsy:
                    return scope
            except AttributeError:
                return scope or ''
        except (AttributeError, KeyError, IndexError, ValueError):
            # We couldn't find the key in the current scope
            # We'll try again on the next pass
            pass

    # We couldn't find the key in any of the scopes
    return ''
571988
def convert_index_to_keys(d, item):
    # use a separate function rather than a method inside the class IndexDict
    '''
    
    '''

    keys = force_list(d.keys())
    # use KeyError for compatibility of normal use

    # Warning: int item will be interpreted as the index rather than key!!
    if isinstance(item, int):
        item = _int_to_key(keys, item)
        single = True

    elif isinstance(item, (tuple, list)):
        item2 = []
        for i in item:
            i = _int_to_key(keys, i)
            item2.append(i)
        item = item2
        single = False

    elif isinstance(item, slice):
        start, stop, step = item.start, item.stop, item.step
        # None is not interpreted as a key
        if not isinstance(start, (NoneType, int)):
            try:
                start = keys.index(start)
            except ValueError:
                raise KeyError('%s is not in the list of keys' % (start,))
        if not isinstance(stop, (NoneType, int)):
            try:
                stop = keys.index(stop)
            except ValueError:
                raise KeyError('%s is not in the list of keys' % (stop,))
        item = keys[start:stop:step]
        single = False

    else:  # other types, treated as a single key
        IndexDict_check_key_type(item)
        single = True

    return item, single
207753
def recursive_map(func, data):
    
    def recurse(item):
        return recursive_map(func, item)
    items_mapped = map_collection(recurse, data)
    return func(items_mapped)
91984
def get_nested_dicts_with_key_containing_value(parent_dict: dict, key, value):
    """"""
    references = []
    NestedLookup(parent_dict, references, NestedLookup.key_value_containing_value_factory(key, value))
    return (document for document, _ in references)
198316
def _flatten_dicts(self, dicts):
        
        d = dict()
        list_of_dicts = [d.get() for d in dicts or []]
        return {k: v for d in list_of_dicts for k, v in d.items()}
393189
def get_index_nested(x, i):
    
    for ind in range(len(x)):
        if i == x[ind]:
            return ind
    return -1