<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _get_terminals_and_nonterminals(sentence_graph):
 """ Given a TigerSentenceGraph, returns a sorted list of terminal node IDs, as well as a sorted list of nonterminal node IDs. Parameters sentence_graph : TigerSentenceGraph a directed graph representing one syntax annotated sentence from a TigerXML file Returns ------- terminals, nonterminals : list of str a sorted list of terminal node IDs and a sorted list of nonterminal node IDs """

    terminals = set()
    nonterminals = set()
    for node_id in sentence_graph.nodes_iter():
        if sentence_graph.out_degree(node_id) > 0:
            # all nonterminals (incl. root)
            nonterminals.add(node_id)
        else:  # terminals
            terminals.add(node_id)
    return sorted(list(terminals), key=natural_sort_key), \
        sorted(list(nonterminals), key=natural_sort_key)