nodes: 0, module; 1, function_definition; 2, function_name:sorted_items; 3, parameters; 4, block; 5, identifier:d; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, comment:# wrap the key func so it operates on the first element of each item; 10, function_definition; 11, return_statement; 12, identifier:key; 13, identifier:__identity; 14, identifier:reverse; 15, False; 16, comment:"""
  	Return the items of the dictionary sorted by the keys
  
  	>>> sample = dict(foo=20, bar=42, baz=10)
  	>>> tuple(sorted_items(sample))
  	(('bar', 42), ('baz', 10), ('foo', 20))
  
  	>>> reverse_string = lambda s: ''.join(reversed(s))
  	>>> tuple(sorted_items(sample, key=reverse_string))
  	(('foo', 20), ('bar', 42), ('baz', 10))
  
  	>>> tuple(sorted_items(sample, reverse=True))
  	(('foo', 20), ('baz', 10), ('bar', 42))
  	"""; 17, function_name:pairkey_key; 18, parameters; 19, block; 20, call; 21, identifier:item; 22, return_statement; 23, identifier:sorted; 24, argument_list; 25, call; 26, call; 27, keyword_argument; 28, keyword_argument; 29, identifier:key; 30, argument_list; 31, attribute; 32, argument_list; 33, identifier:key; 34, identifier:pairkey_key; 35, identifier:reverse; 36, identifier:reverse; 37, subscript; 38, identifier:d; 39, identifier:items; 40, identifier:item; 41, integer:0
code: def sorted_items(d, key=__identity, reverse=False):
  	"""
  	Return the items of the dictionary sorted by the keys
  
  	>>> sample = dict(foo=20, bar=42, baz=10)
  	>>> tuple(sorted_items(sample))
  	(('bar', 42), ('baz', 10), ('foo', 20))
  
  	>>> reverse_string = lambda s: ''.join(reversed(s))
  	>>> tuple(sorted_items(sample, key=reverse_string))
  	(('foo', 20), ('bar', 42), ('baz', 10))
  
  	>>> tuple(sorted_items(sample, reverse=True))
  	(('foo', 20), ('baz', 10), ('bar', 42))
  	"""
  	# wrap the key func so it operates on the first element of each item
  	def pairkey_key(item):
  		return key(item[0])
  	return sorted(d.items(), key=pairkey_key, reverse=reverse)