<｜begin▁of▁sentence｜>### Instruction:
Given a directed graph with edges [(0, 1), (2, 1), (3, 4)], how can we calculate the number of weakly connected components using NetworkX?
### Response:
import networkx as nx

# Create a directed graph
G = nx.DiGraph()

# Add edges
G.add_edges_from([(0, 1), (2, 1), (3, 4)])

# Compute the number of weakly connected components
num_weakly_connected_components = nx.number_weakly_connected_components(G)

print(f'Number of weakly connected components: {num_weakly_connected_components}')
<|EOT|>
