<｜begin▁of▁sentence｜>### Instruction:
Given a directed acyclic graph (DAG) with the edge set [(0, 1, {'cost': 1}), (1, 2, {'cost': 1}), (0, 2, {'cost': 42})], what is the longest path length when considering the 'cost' attribute as the edge weight?
### Response:
import networkx as nx

DG = nx.DiGraph([(0, 1, {'cost': 1}), (1, 2, {'cost': 1}), (0, 2, {'cost': 42})])
length = nx.dag_longest_path_length(DG, weight='cost')
print('Longest path length by cost:', length)
<|EOT|>
