Sort an ordered dictionary by value, descending.

    Args:
        d (OrderedDict): An ordered dictionary.
        desc (bool): If true, sort desc.

    Returns:
        OrderedDict: The sorted dictionary.
193261
def sort_dict(d, desc=True):

    

    sort = sorted(d.items(), key=lambda x: x[1], reverse=desc)
    return OrderedDict(sort)
406639
def dimension_sort(odict, kdims, vdims, key_index):
    
    sortkws = {}
    ndims = len(kdims)
    dimensions = kdims+vdims
    indexes = [(dimensions[i], int(i not in range(ndims)),
                    i if i in range(ndims) else i-ndims)
                for i in key_index]
    cached_values = {d.name: [None]+list(d.values) for d in dimensions}

    if len(set(key_index)) != len(key_index):
        raise ValueError("Cannot sort on duplicated dimensions")
    else:
       sortkws['key'] = lambda x: tuple(cached_values[dim.name].index(x[t][d])
                                        if dim.values else x[t][d]
                                        for i, (dim, t, d) in enumerate(indexes))
    if sys.version_info.major == 3:
        return python2sort(odict.items(), **sortkws)
    else:
        return sorted(odict.items(), **sortkws)
169186
def sort_recursive(data):
    

    newdict = {}

    for i in data.items():
        if type(i[1]) is dict:
            newdict[i[0]] = sort_recursive(i[1])
        else:
            newdict[i[0]] = i[1]

    return OrderedDict(sorted(newdict.items(), key=lambda item: (compare_type(type(item[1])), item[0])))
104019
def sort_by(ascending=true, &block)
      return self.to_enum(:sort_by) unless block_given?
      order = self.map(&block).to_darr.sorted_indices
      order.reverse! unless ascending
      data = @data.map{|darr| darr.sort_by.with_index{|val, i| order.index(i)}}
      index = @index.sort_by.with_index{|val, i| order.index(i)}
      Mikon::DataFrame.new(data, {index: index, labels: @labels})
    end
373563
def sort(self, *, key: Optional[Callable[[Any], Any]] = None, reverse: bool = False) -> None:
        
        return list.sort(self, key=self._sort_key(key), reverse=reverse)
914217
def sort_dict_by_key(obj):
    
    sort_func = lambda x: x[0]
    return OrderedDict(sorted(obj.items(), key=sort_func))
1329382
def last(self, count=1):
        
        if self._order_with:
            order = self._order_with.values()[0]
            order = "desc" if order == "asc" else "asc"
            order_with = self._order_with
            self._order_with = {}
            result = self.order_by(**{order_with.keys()[0]: order}).first(count)
            self._order_with = order_with
            return result
        else:
            return self.order_by(id="desc").first(count)
1158160
def _sort(self):
        
        self._log.debug('Sorting responses by priority')
        self._responses = OrderedDict(sorted(list(self._responses.items()), reverse=True))
        self.sorted = True
1141640
def sort_dict(key_counts, by_key=False):
    ''''''
    sort_key = lambda x: (-1 * x[1], x[0])
    if by_key:
        sort_key = lambda x: x[0]
    return sorted(key_counts.items(), key=sort_key)
782178
def sorted_t(key=None, reverse=False):
    
    return Transformation(
        'sorted',
        lambda sequence: sorted(sequence, key=key, reverse=reverse),
        None
    )
692111
def _order(self, value, is_reverse=None):
        

        def _dict_parser(dict_doc):
            """ dict ordered by:
            valueType_N -> key_N -> value_N
            """
            result = list()
            for key in dict_doc:
                data = self._order(dict_doc[key])
                res = (data[0], key, data[1])
                result.append(res)
            return tuple(result)

        def _list_parser(list_doc):
            """list will iter members to compare
            """
            result = list()
            for member in list_doc:
                result.append(self._order(member))
            return result

        # (TODO) include more data type
        if value is None or not isinstance(value, (dict,
                                                   list,
                                                   basestring,
                                                   bool,
                                                   float,
                                                   int)):
            # not support/sortable value type
            value = (0, None)

        elif isinstance(value, bool):
            value = (5, value)

        elif isinstance(value, (int, float)):
            value = (1, value)

        elif isinstance(value, basestring):
            value = (2, value)

        elif isinstance(value, dict):
            value = (3, _dict_parser(value))

        elif isinstance(value, list):
            if len(value) == 0:
                # [] less then None
                value = [(-1, [])]
            else:
                value = _list_parser(value)

            if is_reverse is not None:
                # list will firstly compare with other doc by it's smallest
                # or largest member
                value = max(value) if is_reverse else min(value)
            else:
                # if the smallest or largest member is a list
                # then compaer with it's sub-member in list index order
                value = (4, tuple(value))

        return value
41505
def natural_sorted(iterable):
    
    def sortkey(x):
        return [(int(c) if c.isdigit() else c) for c in re.split(numbers, x)]

    numbers = re.compile(r'(\d+)')
    return sorted(iterable, key=sortkey)
954994
def _ordered(generator, *args, **kwargs):
    """"""
    unordered_dict = {k: v for k, v in generator(*args, **kwargs)}
    keys = sorted(list(dict(unordered_dict).keys()))
    result = OrderedDict()
    for key in keys:
        result[key] = unordered_dict[key]

    return result
881437
def order_by_descending(self, key):
        
        if key is None:
            raise NullArgumentError(u"No key for sorting given")
        kf = [OrderingDirection(key, reverse=True)]
        return SortedEnumerable3(kf, self._data)
39195
def sorted_dict_repr(d):
    
    keys = list(d.keys())
    keys.sort()
    return "{" + ", ".join(["%r: %r" % (k, d[k]) for k in keys]) + "}"
821002
def reverseDict(d):
    
    retD = {}
    for k in d:
        retD[d[k]] = k
    return retD
738551
def sorted(self, by, **kwargs):
        
        sort_idc = np.argsort(self[by], **kwargs)
        return self.__class__(
            self[sort_idc],
            h5loc=self.h5loc,
            split_h5=self.split_h5,
            name=self.name
        )