<｜begin▁of▁sentence｜>### Instruction:
Given a directed acyclic graph (DAG) with edge set [(2, 1), (2, 5), (1, 3), (1, 4), (5, 4)], how can you generate a lexicographical topological sort of the nodes, and how can the sort be customized using a custom key function?
### Response:
import networkx as nx

# Create a directed acyclic graph (DAG)
DG = nx.DiGraph([(2, 1), (2, 5), (1, 3), (1, 4), (5, 4)])

# Perform a lexicographical topological sort and print the sorted nodes
sorted_nodes = list(nx.lexicographical_topological_sort(DG))
print(f'Lexicographically sorted nodes: {sorted_nodes}')

# Perform a lexicographical topological sort with a custom key function
sorted_nodes_custom_key = list(nx.lexicographical_topological_sort(DG, key=lambda x: -x))
print(f'Lexicographically sorted nodes with custom key: {sorted_nodes_custom_key}')
<|EOT|>
