Serializes a dict-like object into a generator of the flatten list of
    repeating key-value pairs.  It is useful when using HMSET method in Redis.

    Example:
    >>> list(dict2kvlist({'a': 1, 'b': 2}))
    ['a', 1, 'b', 2]
348006
def dict2kvlist(o):
    '''
    
    '''
    return chain.from_iterable((k, v) for k, v in o.items())
319405
def serialize(self, items):
        
        r = StringIO()
        for key, value in items.items():
            if isinstance(value, list):
                # handle special case of lists
                value = "["+", ".join(map(str, value))+"]"
            r.write("%s = %s\n" % (key, value))
        return r.getvalue()
1331860
def flatten(self, obj):
        
        return [self._serialize(f, obj) for f in self.fields]
1103453
def list_to_serialized(ref, the_list):
    
    result = []
    for elt in the_list:
        if not getattr(elt, 'serialize', None):
            continue
        result.append(elt.serialize())
    return result
942258
def flatten(self, D):
        '''
        '''

        if not isinstance(D, dict):
            return D

        result = {}
        for k,v in D.items():
            if isinstance(v, dict):
                for _k,_v in self.flatten(v).items():
                    result['.'.join([k,_k])] = _v
            else:
                result[k] = v
        return result
925141
def transpose_list(list_of_dicts):
    
    res = {}
    for d in list_of_dicts:
        for k, v in d.items():
            if k in res:
                res[k].append(v)
            else:
                res[k] = [v]
    return res
1110273
def flatten_list(l):
    
    return list(chain.from_iterable(repeat(x,1) if isinstance(x,str) else x for x in l))
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
768528
def ToHashArray(self):
        
        hashes = set()
        MerkleTree.__DepthFirstSearch(self.Root, hashes)
        return list(hashes)
1057189
def _serialize_list(cls, list_):
        

        list_serialized = []

        for item in list_:
            item_serialized = cls.serialize(item)
            list_serialized.append(item_serialized)

        return list_serialized
1114420
def generate_flattened_dict(headers, results):
    ''''''
    for name, values in results.items():
        row = []
        for header in headers:
            if header == 'name':
                row.append(name)
            elif ':' in header:
                neurite_type, metric = header.split(':')
                row.append(values[neurite_type][metric])
            else:
                row.append(values[header])
        yield row
174469
private String _serializeList(List list, Map<Object, String> done, String id) throws ConverterException {
	// <ARRAY ID="1" SIZE="1"><ITEM INDEX="1" TYPE="STRING">hello world</ITEM></ARRAY>
	StringBuilder sb = new StringBuilder(goIn() + "<ARRAY ID=\"" + id + "\" SIZE=" + del + list.size() + del + ">");
	int index;
	ListIterator it = list.listIterator();
	while (it.hasNext()) {
	    // <ITEM INDEX="1" TYPE="STRING">hello world</ITEM>
	    index = it.nextIndex();
	    String value = _serialize(it.next(), done);
	    sb.append(goIn() + "<ITEM INDEX=\"" + (index + 1) + "\" TYPE=\"" + type + "\">");
	    sb.append(value);
	    sb.append(goIn() + "</ITEM>");
	}

	sb.append(goIn() + "</ARRAY>");
	type = "ARRAY";
	return sb.toString();
    }
220519
def _dict_to_list_ids(objects):
    '''
    
    '''
    list_with_ids = []
    for key, value in six.iteritems(objects):
        element = {'id': key}
        element.update(value)
        list_with_ids.append(element)
    return list_with_ids
99760
def dump_dict_of_nested_lists_to_h5(fname, data):
    
    # Open file
    print('writing to file: %s' % fname)
    f = h5py.File(fname)
    # Iterate over values
    for i, ivalue in list(data.items()):
        igrp = f.create_group(str(i))
        for j, jvalue in enumerate(ivalue):
            jgrp = igrp.create_group(str(j))
            for k, kvalue in enumerate(jvalue):
                if kvalue.size > 0:
                    dset = jgrp.create_dataset(str(k), data=kvalue,
                                               compression='gzip')
                else:
                    dset = jgrp.create_dataset(str(k), data=kvalue,
                                               maxshape=(None, ),
                                               compression='gzip')
    # Close file
    f.close()
863952
def flatten_repetition(list, named)
      if list.any? { |e| e.instance_of?(Hash) }
        # If keyed subtrees are in the array, we'll want to discard all 
        # strings inbetween. To keep them, name them. 
        return list.select { |e| e.instance_of?(Hash) }
      end

      if list.any? { |e| e.instance_of?(Array) }
        # If any arrays are nested in this array, flatten all arrays to this
        # level. 
        return list.
          select { |e| e.instance_of?(Array) }.
          flatten(1)
      end

      # Consistent handling of empty lists, when we act on a named result        
      return [] if named && list.empty?

      # If there are only strings, concatenate them and return that. 
      foldl(list.compact) { |s,e| s+e }
    end
1230585
def _recursive_repr(item):
    
    if isinstance(item, basestring):
        result = str(item)
    elif isinstance(item, list):
        result = '[{}]'.format(', '.join([_recursive_repr(x) for x in item]))
    elif isinstance(item, dict):
        kv_pairs = ['{}: {}'.format(_recursive_repr(k), _recursive_repr(item[k])) for k in sorted(item)]
        result = '{' + ', '.join(kv_pairs) + '}'
    else:
        result = repr(item)
    return result
1077764
def dict_to_table(dictionary, list_of_keys=None):
    

    # assert len(dictionary.values()) > 0, "Dictionary cannot be empty"

    # Create an empty table

    table = Table()

    # If the dictionary is not empty, fill the table

    if len(dictionary) > 0:

        # Add the names as first column

        table['name'] = dictionary.keys()

        # Now add all other properties

        # Use the first parameter as prototype

        prototype = dictionary.values()[0]

        column_names = prototype.keys()

        # If we have a white list for the columns, use it

        if list_of_keys is not None:

            column_names = filter(lambda key: key in list_of_keys, column_names)

        # Fill the table

        for column_name in column_names:

            table[column_name] = map(lambda x: x[column_name], dictionary.values())

    return table