<｜begin▁of▁sentence｜>### Instruction:
Given a directed graph with edges [('A', 'B', {'weight': 2}), ('B', 'A', {'weight': 3}), ('B', 'C', {'weight': 4})], how can you convert it to an undirected graph in NetworkX, where reciprocal edges have their weights summed up?
### Response:
import networkx as nx

# Create a directed graph using NetworkX
dg = nx.DiGraph()
# Add some edges to the directed graph
dg.add_edge('A', 'B', weight=2)
dg.add_edge('B', 'A', weight=3)
dg.add_edge('B', 'C', weight=4)
# Convert the directed graph to an undirected graph
g = dg.to_undirected(reciprocal=True)
# Merge the reciprocal edges by summing the weights
for u, v, d in g.edges(data=True):
    if g.has_edge(v, u):
        d['weight'] += g[v][u]['weight']
g = nx.Graph(g)  # To remove parallel edges and self-loops
# Print the undirected graph with combined weights
print(g.edges(data=True))
<|EOT|>
