Sorts a dictionary containing data for a single reference into a standard order
481917
def sort_single_reference(ref_entry):
    

    # yapf: disable
    _keyorder = [
        # Schema stuff
        # This function gets called on the schema 'entry', too
        'schema_type', 'schema_version',

        # Type of the entry
        'type',

        # Actual publication info
        'authors', 'title', 'booktitle', 'series', 'editors', 'journal',
        'institution', 'volume', 'number', 'page', 'year', 'note', 'publisher',
        'address', 'isbn', 'doi'
    ]
    # yapf: enable

    sorted_entry = sorted(ref_entry.items(), key=lambda x: _keyorder.index(x[0]))

    if _use_odict:
        return OrderedDict(sorted_entry)
    else:
        return dict(sorted_entry)
977702
function sortData(unorderedData) {
            let {data, dataZeroed} = unorderedData;

            if (orderingFunction) {
                data.sort(orderingFunction);
                dataZeroed.sort(orderingFunction)
            }

            return { data, dataZeroed };
        }
321325
def ordered_dict_to_dict(d):
    
    ret = {}
    new_d = deepcopy(d)
    for k, v in new_d.items():
        if isinstance(v, OrderedDict):
            v = dict(v)
        if isinstance(v, dict):
            v = ordered_dict_to_dict(v)
        ret[k] = v
    return ret
1151279
def _sort(self, short_list, sorts):
        

        sort_values = self._index_columns(sorts)

        # RECURSIVE SORTING
        output = []
        def _sort_more(short_list, i, sorts):
            if len(sorts) == 0:
                output.extend(short_list)

            sort = sorts[0]

            index = self._index[sort_values[i]]
            if sort.sort == 1:
                sorted_keys = sorted(index.keys())
            elif sort.sort == -1:
                sorted_keys = reversed(sorted(index.keys()))
            else:
                sorted_keys = list(index.keys())

            for k in sorted_keys:
                self._sort(index[k] & short_list, i + 1, sorts[1:])

        _sort_more(short_list, 0, sorts)
        return output
791987
def re_sort(data):
    
    keys = sorted(data.keys())
    new_data = {}
    for number, key in enumerate(keys):
        new_data[number] = data[key]
    return new_data
614254
def str2dict_keys(str_in):
    '''
    
    '''
    tmp_dict = str2dict(str_in)
    if tmp_dict is None:
        return None
    return sorted([k for k in tmp_dict])
1329667
def clean_dict(d, test=lambda v: v):
    
    return {k: v for k, v in d.items() if test(v)}
1354473
def sort_func(self, key):
        """"""
        if key == self._KEYS.TIME:
            return 'aaa'
        if key == self._KEYS.DATA:
            return 'zzy'
        if key == self._KEYS.SOURCE:
            return 'zzz'
        return key
448428
def ordered(obj):
    
    if isinstance(obj, collections.abc.Mapping):
        return sorted((k, ordered(v)) for k, v in obj.items())
    # Special case str since it's a collections.abc.Iterable
    elif isinstance(obj, str):
        return obj
    elif isinstance(obj, collections.abc.Iterable):
        return sorted(ordered(x) for x in obj)
    else:
        return obj
14555
def as_ordereddict(self):
        """"""
        if six.PY2:
            d = OrderedDict()
            copied = dict(self)
            for key in self:
                d[key] = copied[key]
        else:
            d = OrderedDict(self)
        return d
914217
def sort_dict_by_key(obj):
    
    sort_func = lambda x: x[0]
    return OrderedDict(sorted(obj.items(), key=sort_func))
96327
def sort_by_type(file_list):
    
    ret_dict = defaultdict(list)
    for filepath in file_list:
        _, ext = os.path.splitext(filepath)
        ret_dict[ext.replace('.', '')].append(filepath)

    return ret_dict
692178
def sortby(self, ntd):
        """"""
        if 'reldepth' in self.grprobj.gosubdag.prt_attr['flds']:
            return [ntd.NS, -1*ntd.dcnt, ntd.reldepth]
        else:
            return [ntd.NS, -1*ntd.dcnt, ntd.depth]
1111421
def convert_references(ref_data, fmt):
    '''
    
    '''

    # Make fmt case insensitive
    fmt = fmt.lower()
    if fmt not in _converter_map:
        raise RuntimeError('Unknown reference format "{}"'.format(fmt))

    # Sort the data for all references
    for elref in ref_data:
        for rinfo in elref['reference_info']:
            rdata = rinfo['reference_data']
            rinfo['reference_data'] = [(k, sort.sort_single_reference(v)) for k, v in rdata]

    # Actually do the conversion
    ret_str = _converter_map[fmt]['function'](ref_data)

    return ret_str
15855
def repr_dict(_dict, indent):
    """"""
    # pprint represents OrderedDict objects using the tuple init syntax,
    # which is not very readable. Therefore, dictionaries are iterated over.
    if _dict is None:
        return 'None'
    if not isinstance(_dict, Mapping):
        raise TypeError("Object must be a mapping, but is a %s" %
                        type(_dict))
    if isinstance(_dict, OrderedDict):
        kind = 'ordered'
        ret = '%s {\n' % kind  # non standard syntax for the kind indicator
        for key in six.iterkeys(_dict):
            value = _dict[key]
            ret += _indent('%r: %r,\n' % (key, value), 2)
    else:  # dict
        kind = 'sorted'
        ret = '%s {\n' % kind  # non standard syntax for the kind indicator
        for key in sorted(six.iterkeys(_dict)):
            value = _dict[key]
            ret += _indent('%r: %r,\n' % (key, value), 2)
    ret += '}'
    ret = repr_text(ret, indent=indent)
    return ret.lstrip(' ')
1170818
def sort_items(items):
    """"""

    sorted_items = {}
    for item in items:
        category = lookup(item, 'itemCategory', 'categoryCode')
        if sorted_items.get(category) is None:
            sorted_items[category] = []
        sorted_items[category].append(item)

    return sorted_items
804623
def todict(self):
        """"""
        return OrderedDict((name, self[i]) for i, name in enumerate(self._fields))