A generator that takes a enumerable item and returns a series of
    slices. Useful for turning a list into a series of rows. 

    >>> list(list_to_rows([1, 2, 3, 4, 5, 6, 7], 3))
    [[1, 2, 3], [4, 5, 6], [7, ]]
777807
def list_to_rows(src, size):
    

    row = []
    for item in src:
        row.append(item)
        if len(row) == size:
            yield row
            row = []

    if row:
        yield row
1223618
def chunks_of(max_chunk_size, list_to_chunk):
    
    for i in range(0, len(list_to_chunk), max_chunk_size):
        yield list_to_chunk[i:i + max_chunk_size]
391927
def flatten(input_list):
    
    for el in input_list:
        if isinstance(el, collections.Iterable) \
                and not isinstance(el, basestring):
            for sub in flatten(el):
                yield sub
        else:
            yield el
1368742
def flatten(nested, containers=(list, tuple)):
    
    for item in nested:
        if hasattr(item, "next") or isinstance(item, containers):
            for subitem in flatten(item):
                yield subitem
        else:
            yield item
1351811
def flatten_iterable(iterable):
    
    for item in iterable:
        if isinstance(item, collections.Iterable) and not isinstance(item, basestring):
            for sub in flatten_iterable(item):
                yield sub
        else:
            yield item
756482
def concat(cls, iterables):
    

    def generator():
      for it in iterables:
        for element in it:
          yield element
    return cls(generator())
651639
def chain(cls, *iterables):
    

    def generator():
      for it in iterables:
        for element in it:
          yield element
    return cls(generator())
243970
def flatten(nested_list):
    ''''''
    return_list = []
    for i in nested_list:
        if isinstance(i,list):
            return_list += flatten(i)
        else:
            return_list.append(i)
    return return_list
306956
def to_object(item):
        
        def convert(item): 
            if isinstance(item, dict):
                return IterableObject({k: convert(v) for k, v in item.items()})
            if isinstance(item, list):
                def yield_convert(item):
                    for index, value in enumerate(item):
                        yield convert(value)
                return list(yield_convert(item))
            else:
                return item

        return convert(item)
1075325
def groups_of(n, iterable):
    
    args = [iter(iterable)] * n
    for x in izip_longest(*args):
        yield [v for v in x if v is not None]
132104
def to_list(item_or_list):
    
    if isinstance(item_or_list, list):
        return item_or_list
    elif isinstance(item_or_list, (str, bytes)):
        return [item_or_list]
    elif isinstance(item_or_list, Iterable):
        return list(item_or_list)
    else:
        return [item_or_list]
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
988976
def generator_to_list(fn):
    
    def wrapper(*args, **kw):
        return list(fn(*args, **kw))
    return wrapper
131824
def to_dict(item):
        
        def convert(item):
            if isinstance(item, IterableObject):
                if isinstance(item.source, dict):
                    return {k: convert(v.source) if hasattr(v, 'source') else convert(v) for k, v in item}
                else:
                    return convert(item.source)
            elif isinstance(item, dict):
                return {k: convert(v) for k, v in item.items()}
            elif isinstance(item, list):
                def yield_convert(item):
                    for index, value in enumerate(item):
                        yield convert(value)
                return list(yield_convert(item))
            else:
                return item

        return convert(item)
582609
def _items(self):
        
        torrents = map(self._get_torrent, self._get_rows())

        for t in torrents:
            yield t
661775
def make_list(obj, cast=True):
    
    if isinstance(obj, list):
        return list(obj)
    if isinstance(obj, types.GeneratorType):
        return list(obj)
    if isinstance(obj, (tuple, set)) and cast:
        return list(obj)
    else:
        return [obj]
834008
def slices(self):
        
        if self.chunks is None:
            yield tuple(slice(None, s) for s in self.shape)
        else:
            ceilings = tuple(-(-s // c) for s, c in zip(self.shape, self.chunks))
            for idx in np.ndindex(ceilings):  # could also use itertools.product
                out = []
                for i, c, s in zip(idx, self.chunks, self.shape):
                    start = i * c
                    stop = min(start + c, s + 1)
                    out.append(slice(start, stop, 1))
                yield tuple(out)