Recursively converts iterables into tuples.

  Args:
    nested: A nested structure of items and iterables.

  Returns:
    A nested structure of items and tuples.
553572
def tuplize(nested):
  
  if isinstance(nested, str):
    return nested
  try:
    return tuple(map(tuplize, nested))
  except TypeError:
    return nested
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
359006
def flatten_if(cond: Callable[[Union[T, ActualIterable[T]]], bool]):
    

    def inner(nested: ActualIterable[Union[T, ActualIterable[T]]]) -> ActualIterable[T]:
        for each in nested:
            if cond(each):
                yield from inner(each)
            else:
                yield each

    return inner
691075
def _nest_payload(self, keys, payload):
        
        if len(keys) == 0:
            return payload

        return {keys[0]: self._nest_payload(keys[1:], payload)}
82865
def chunks(items, n):
    
    it = iter(items)
    chunk = tuple(itertools.islice(it, n))
    while chunk:
        yield chunk
        chunk = tuple(itertools.islice(it, n))
1188681
def from_dict(self, data, recursive=1):
        
        # Find other linked resources
        data = self._encode_resource(data, recursive=recursive)
        self.data = data
626910
def flatten(items):
    
    for x in items:
        if isinstance(x, Iterable) and not isinstance(x, (str, bytes)):
            for sub_x in flatten(x):
                yield sub_x
        else:
            yield x
605769
def seq_list_nested(b, d, x=0, top_level=True):
    '''
    
    '''
    x += 1

    if d == 0:
        ret = [x]
    else:
        val = x
        ret = []
        for i in range(b):
            lst, x = seq_list_nested(b, d-1, x, False)
            ret.extend(lst)
        ret = [val, ret]
            
    if top_level:
        return ret
    else:
        return ret, x
743002
def _convert_nest_to_flat(self, params, _result=None, _prefix=None):
        
        if _result is None:
            _result = {}
        for k, v in params.iteritems():
            if _prefix is None:
                path = k
            else:
                path = _prefix + '.' + k
            if isinstance(v, dict):
                self._convert_nest_to_flat(v, _result=_result, _prefix=path)
            else:
                _result[path] = v
        return _result
616362
def collection_keys(coll, sep='.'):
    
    def _keys(x, pre=''):
        for k in x:
            yield (pre + k)
            if isinstance(x[k], dict):
                for nested in _keys(x[k], pre + k + sep):
                    yield nested

    return list(_keys(coll.find_one()))
808887
def nested_join(array, o_str= '{', c_str= '}'):
    '''
        
    '''
    result = ''
    for x in array :
        if type(x) == type([])  :
            result  +=o_str+ nested_join(x)+ c_str
        else                    :
            result  +=x
    return result
186814
def get_nested_streams(dmap):
    
    return list({s for dmap in get_nested_dmaps(dmap) for s in dmap.streams})
1041437
def _from_json_array_nested(cls, response_raw):
        

        json = response_raw.body_bytes.decode()
        obj = converter.json_to_class(dict, json)
        value = converter.deserialize(cls, obj[cls._FIELD_RESPONSE])

        return client.BunqResponse(value, response_raw.headers)
756972
def to_dict(self, nested=False):
        
        result = dict()
        for key in self.columns:
            result[key] = getattr(self, key)

        if nested:
            for key in self.relations:
                obj = getattr(self, key)

                if isinstance(obj, SerializeMixin):
                    result[key] = obj.to_dict()
                elif isinstance(obj, Iterable):
                    result[key] = [o.to_dict() for o in obj]

        return result
19954
def flatten_items(items, recurse=False):
    

    if not items:
        return items
    elif not hasattr(items, '__iter__'):
        return items
    elif isinstance(items, _flattened_types):
        return items

    flattened = []
    for item in items:
        if item and hasattr(item, '__iter__') and not isinstance(item, _flattened_types):
            flattened.extend(flatten_items(item, True) if recurse else item)
        else:
            flattened.append(item)

    return type(items)(flattened) if isinstance(items, _flatten_types) else flattened
1354584
def set_nested(self, klist, value):
        """"""
        keys = list(klist)
        if len(keys) > 0:
            curr_dict = self
            last_key = keys.pop()
            for key in keys:
                if not curr_dict.has_key(key) or not isinstance(curr_dict[key], 
                                                                NestedDict):
                    curr_dict[key] = type(self)()
                curr_dict = curr_dict[key]
            curr_dict[last_key] = value
520453
def nested_in(*names, &block)
      options = names.extract_options!
      raise ArgumentError, "when giving more than one nesting, you may not specify options or a block" if names.length > 1 and (block_given? or options.length > 0)

      # convert :polymorphic option to '?'
      if options.delete(:polymorphic)
        raise ArgumentError, "when specifying :polymorphic => true, no block or other options may be given" if block_given? or options.length > 0
        names = ["?#{names.first}"]
      end

      # ignore first '*' if it has already been specified by :load_enclosing == true
      names.shift if specifications == ['*'] && names.first == '*'

      names.each do |name|
        ensure_sane_wildcard if name == '*'
        specifications << (name.to_s =~ /^(\*|\?(.*))$/ ? name.to_s : Specification.new(name, options, &block))
      end
    end