<｜begin▁of▁sentence｜>### Instruction:
Given a directed graph with edge set [(0, 1), (2, 1), (3, 4)], compute the number of weakly connected components using NetworkX.
### Response:
import networkx as nx

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

# Add edges
G.add_edge(0, 1)
G.add_edge(2, 1)
G.add_edge(3, 4)

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

print('Number of weakly connected components:', components)
<|EOT|>
