nodes: 0, module; 1, function_definition; 2, function_name:_sort_policy; 3, parameters; 4, block; 5, identifier:doc; 6, expression_statement; 7, if_statement; 8, return_statement; 9, string; 10, call; 11, block; 12, elif_clause; 13, identifier:doc; 14, string_content:List-type sub-items in policies don't happen to be order-sensitive, but
      compare operations will render them unequal, leading to non-idempotent
      state runs.  We'll sort any list-type subitems before comparison to reduce
      the likelihood of false negatives.; 15, identifier:isinstance; 16, argument_list; 17, return_statement; 18, call; 19, block; 20, identifier:doc; 21, identifier:list; 22, call; 23, identifier:isinstance; 24, argument_list; 25, return_statement; 26, identifier:sorted; 27, argument_list; 28, identifier:doc; 29, tuple; 30, call; 31, list_comprehension; 32, identifier:dict; 33, identifier:OrderedDict; 34, identifier:dict; 35, argument_list; 36, call; 37, for_in_clause; 38, list_comprehension; 39, identifier:_sort_policy; 40, argument_list; 41, identifier:i; 42, identifier:doc; 43, tuple; 44, for_in_clause; 45, identifier:i; 46, identifier:k; 47, call; 48, pattern_list; 49, call; 50, identifier:_sort_policy; 51, argument_list; 52, identifier:k; 53, identifier:v; 54, attribute; 55, argument_list; 56, identifier:v; 57, identifier:six; 58, identifier:iteritems; 59, identifier:doc
code: def _sort_policy(doc):
      '''
      List-type sub-items in policies don't happen to be order-sensitive, but
      compare operations will render them unequal, leading to non-idempotent
      state runs.  We'll sort any list-type subitems before comparison to reduce
      the likelihood of false negatives.
      '''
      if isinstance(doc, list):
          return sorted([_sort_policy(i) for i in doc])
      elif isinstance(doc, (dict, OrderedDict)):
          return dict([(k, _sort_policy(v)) for k, v in six.iteritems(doc)])
      return doc