<｜begin▁of▁sentence｜>### Instruction:
Given a graph with weighted edges [('A', 'B', 4), ('B', 'C', 2), ('A', 'C', 5), ('C', 'D', 1)], can you compute the shortest paths between all pairs of nodes using the Bellman-Ford algorithm?
### Response:
import networkx as nx

# Create a weighted graph
G = nx.Graph()
G.add_edge('A', 'B', weight=4)
G.add_edge('B', 'C', weight=2)
G.add_edge('A', 'C', weight=5)
G.add_edge('C', 'D', weight=1)

# Compute shortest paths between all nodes
paths = dict(nx.all_pairs_bellman_ford_path(G, weight='weight'))
for source, path_dict in paths.items():
    print(f'Shortest paths from {source}:')
    for target, path in path_dict.items():
        print(f'  to {target}: {path}')
<|EOT|>
