nodes: 0, module; 1, function_definition; 2, function_name:to_display_list; 3, parameters; 4, block; 5, identifier:pairs; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, for_statement; 12, comment:# add the empty option; 13, if_statement; 14, comment:# sort by key/value; 15, if_statement; 16, return_statement; 17, identifier:sort_by; 18, string:"key"; 19, identifier:allow_empty; 20, True; 21, comment:"""Create a Plone DisplayList from list items
  
      :param pairs: list of key, value pairs
      :param sort_by: Sort the items either by key or value
      :param allow_empty: Allow to select an empty value
      :returns: Plone DisplayList
      """; 22, assignment; 23, call; 24, block; 25, identifier:pair; 26, identifier:pairs; 27, comment:# pairs is a list of lists -> add each pair; 28, block; 29, identifier:allow_empty; 30, block; 31, comparison_operator:sort_by == "key"; 32, block; 33, elif_clause; 34, identifier:dl; 35, identifier:dl; 36, call; 37, identifier:isinstance; 38, argument_list; 39, expression_statement; 40, if_statement; 41, comment:# pairs is just a single pair -> add it and stop; 42, if_statement; 43, expression_statement; 44, identifier:sort_by; 45, string:"key"; 46, expression_statement; 47, comparison_operator:sort_by == "value"; 48, block; 49, identifier:DisplayList; 50, argument_list; 51, identifier:pairs; 52, identifier:basestring; 53, assignment; 54, call; 55, block; 56, call; 57, block; 58, call; 59, assignment; 60, identifier:sort_by; 61, string:"value"; 62, expression_statement; 63, identifier:pairs; 64, list; 65, identifier:isinstance; 66, argument_list; 67, expression_statement; 68, identifier:isinstance; 69, argument_list; 70, expression_statement; 71, break_statement; 72, attribute; 73, argument_list; 74, identifier:dl; 75, call; 76, assignment; 77, identifier:pairs; 78, identifier:pairs; 79, identifier:pair; 80, tuple; 81, call; 82, identifier:pair; 83, identifier:basestring; 84, call; 85, identifier:dl; 86, identifier:add; 87, string:""; 88, string:""; 89, attribute; 90, argument_list; 91, identifier:dl; 92, call; 93, identifier:tuple; 94, identifier:list; 95, attribute; 96, argument_list; 97, attribute; 98, argument_list; 99, identifier:dl; 100, identifier:sortedByKey; 101, attribute; 102, argument_list; 103, identifier:dl; 104, identifier:add; 105, list_splat; 106, identifier:dl; 107, identifier:add; 108, list_splat; 109, identifier:dl; 110, identifier:sortedByValue; 111, identifier:pair; 112, identifier:pairs
code: def to_display_list(pairs, sort_by="key", allow_empty=True):
      """Create a Plone DisplayList from list items
  
      :param pairs: list of key, value pairs
      :param sort_by: Sort the items either by key or value
      :param allow_empty: Allow to select an empty value
      :returns: Plone DisplayList
      """
      dl = DisplayList()
  
      if isinstance(pairs, basestring):
          pairs = [pairs, pairs]
      for pair in pairs:
          # pairs is a list of lists -> add each pair
          if isinstance(pair, (tuple, list)):
              dl.add(*pair)
          # pairs is just a single pair -> add it and stop
          if isinstance(pair, basestring):
              dl.add(*pairs)
              break
  
      # add the empty option
      if allow_empty:
          dl.add("", "")
  
      # sort by key/value
      if sort_by == "key":
          dl = dl.sortedByKey()
      elif sort_by == "value":
          dl = dl.sortedByValue()
  
      return dl