Predicate checking for ordered dictionaries. OrderedDict is always
    ordered, and vanilla Python dictionaries are ordered for Python 3.6+
192769
def is_ordered_dict(d):
    
    py3_ordered_dicts = (sys.version_info.major == 3) and (sys.version_info.minor >= 6)
    vanilla_odicts = (sys.version_info.major > 3) or py3_ordered_dicts
    return isinstance(d, (OrderedDict))or (vanilla_odicts and isinstance(d, dict))
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
843569
def tag_dict(obj, *args, **kwargs):
    """"""

    if isinstance(obj, OrderedDict):
        return _TaggedOrderedDict(obj, *args, **kwargs)
    else:
        return _TaggedPlainDict(obj, *args, **kwargs)
500206
function sortedKeys(dictionary) {
  let keys = [];
  for (let key in dictionary) {
    keys.push(key);
  }
  return keys.sort();
}
826915
function _residuePredicates(dict) {
  var predicates = [];
  if (dict.rname !== undefined) {
    predicates.push(function(r) { return r.name() === dict.rname; });
  }
  if (dict.rnames !== undefined) {
    predicates.push(function(r) { 
    var n = r.name();
    for (var k = 0; k < dict.rnames.length; ++k) {
      if (n === dict.rnames[k]) {
          return true;
        }
      }
      return false;
    });
  }
  if (dict.rnums !== undefined) {
    var num_set = {};
    for (var i = 0; i < dict.rnums.length; ++i) {
      num_set[dict.rnums[i]] = true;
    }
    predicates.push(function(r) {
      var n = r.num();
      return num_set[n] === true;
    });
  }
  if (dict.rnum !== undefined) {
    predicates.push(function(r) {
      return r.num() === dict.rnum;
    });
  }
  if (dict.rtype !== undefined) {
    predicates.push(function(r) {
      return r.ss() === dict.rtype;
    });
  }
  return predicates;
}
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)
92588
def getIndex(predicateFn: Callable[[T], bool], items: List[T]) -> int:
    
    try:
        return next(i for i, v in enumerate(items) if predicateFn(v))
    except StopIteration:
        return -1
100821
def dict_check(*args, func=None):
    """"""
    func = func or inspect.stack()[2][3]
    for var in args:
        if not isinstance(var, (dict, collections.UserDict, collections.abc.MutableMapping)):
            name = type(var).__name__
            raise DictError(
                f'Function {func} expected dict, {name} got instead.')
264108
def _asdict(self):
        """"""
        return OrderedDict((f.name, getattr(self, f.name))
                           for f in self._struct)
578551
def expr_order_key(expr):
    """"""
    if hasattr(expr, '_order_key'):
        return expr._order_key
    try:
        if isinstance(expr.kwargs, OrderedDict):
            key_vals = expr.kwargs.values()
        else:
            key_vals = [expr.kwargs[key] for key in sorted(expr.kwargs)]
        return KeyTuple((expr.__class__.__name__, ) +
                        tuple(map(expr_order_key, expr.args)) +
                        tuple(map(expr_order_key, key_vals)))
    except AttributeError:
        return str(expr)
392611
def module_functions(modulestr):
    

    funcs = dict(inspect.getmembers(import_module(modulestr),
                 inspect.isfunction))

    return OrderedDict(sorted(funcs.items(), key=lambda f: f[0]))
1089150
def compare_numpy_dict(a, b, exact=True):
    
    if type(a) != type(b) and type(a) != np.ndarray and type(b) != np.ndarray:
        return False
    # go through a dictionary
    if type(a) == dict and type(b) == dict:
        if not a.keys() == b.keys():
            return False
        for key in a.keys():
            res = compare_numpy_dict(a[key], b[key], exact)
            if res == False:
                print("false for key = ", key)
                return False
        return True

    # if type(a) == np.ndarray and type(b) == np.ndarray:
    if type(a) == np.ndarray or type(b) == np.ndarray:
        if exact:
            return (a == b).all()
        else:
            return np.testing.assert_almost_equal(a, b)

    if a is None and b is None:
        return True

    raise NotImplementedError
1003008
def _strip_nones(d: Dict[str, Any])-> Dict[str, Any]:
        
        return OrderedDict({k: None if isinstance(v, JSGNull) else v for k, v in d.items()
                            if not k.startswith("_") and v is not None and v is not Empty and
                            (issubclass(type(v), JSGObject) or
                             (not issubclass(type(v), JSGString) or v.val is not None) and
                             (not issubclass(type(v), AnyType) or v.val is not Empty))})
64121
def is_ordered_mapping(obj):
    
    if not (is_mapping(obj) and hasattr(obj, '__reversed__')):
        return False

    # PyPy has a bug where the standard :class:`dict` has the ``__reversed__``
    # method but it's unusable and throws an exception when called
    try:
        obj.__reversed__()
    except TypeError:
        return False
    else:
        return True
509033
def _check_loop(self, obj, check_mod_str):
        ''''''
        check_module = self._check_modules[check_mod_str]
        checks = self._config['checks'][check_mod_str]
        result = True
        summary = OrderedDict()
        for check in checks:
            ok = self._do_check(obj, check_module, check)
            summary[ok.title] = ok.status
            result &= ok.status

        return result, summary
1209980
def is_list_of_dict_like(obj, attr=('keys', 'items')):
    
    try:
        if len(obj) == 0:
            return False
        return all([is_dict_like(i, attr) for i in obj])
    except Exception:
        return False
1036272
function orderObject (unordered) {
  const ordered = {}
  if (typeof unordered !== 'object' || unordered == null || Array.isArray(unordered)) return unordered
  Object.keys(unordered).sort().forEach(function (key) {
    ordered[key] = ((typeof unordered[key] === 'object') && !Array.isArray(unordered[key])) ? orderObject(unordered[key]) : unordered[key]
  })
  return ordered
}