nodes: 0, module; 1, function_definition; 2, function_name:sort_dict; 3, parameters; 4, block; 5, identifier:d; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, comment:# Sort kv_items according to key.; 11, if_statement; 12, comment:# Build ordered dict.; 13, return_statement; 14, identifier:key; 15, None; 16, identifier:reverse; 17, False; 18, comment:"""
      Sorts a dict by value.
  
      Args:
          d: Input dictionary
          key: Function which takes an tuple (key, object) and returns a value to
              compare and sort by. By default, the function compares the values
              of the dict i.e. key = lambda t : t[1]
          reverse: Allows to reverse sort order.
  
      Returns:
          OrderedDict object whose keys are ordered according to their value.
      """; 19, assignment; 20, comparison_operator:key is None; 21, block; 22, else_clause; 23, call; 24, identifier:kv_items; 25, list_comprehension; 26, identifier:key; 27, None; 28, expression_statement; 29, block; 30, attribute; 31, argument_list; 32, identifier:kv; 33, for_in_clause; 34, call; 35, expression_statement; 36, identifier:collections; 37, identifier:OrderedDict; 38, identifier:kv_items; 39, identifier:kv; 40, call; 41, attribute; 42, argument_list; 43, call; 44, attribute; 45, argument_list; 46, identifier:kv_items; 47, identifier:sort; 48, keyword_argument; 49, keyword_argument; 50, attribute; 51, argument_list; 52, identifier:d; 53, identifier:items; 54, identifier:key; 55, lambda; 56, identifier:reverse; 57, identifier:reverse; 58, identifier:kv_items; 59, identifier:sort; 60, keyword_argument; 61, keyword_argument; 62, lambda_parameters; 63, subscript; 64, identifier:key; 65, identifier:key; 66, identifier:reverse; 67, identifier:reverse; 68, identifier:t; 69, identifier:t; 70, integer:1
code: def sort_dict(d, key=None, reverse=False):
      """
      Sorts a dict by value.
  
      Args:
          d: Input dictionary
          key: Function which takes an tuple (key, object) and returns a value to
              compare and sort by. By default, the function compares the values
              of the dict i.e. key = lambda t : t[1]
          reverse: Allows to reverse sort order.
  
      Returns:
          OrderedDict object whose keys are ordered according to their value.
      """
      kv_items = [kv for kv in d.items()]
  
      # Sort kv_items according to key.
      if key is None:
          kv_items.sort(key=lambda t: t[1], reverse=reverse)
      else:
          kv_items.sort(key=key, reverse=reverse)
  
      # Build ordered dict.
      return collections.OrderedDict(kv_items)