<｜begin▁of▁sentence｜>### Instruction:
Given a graph with weighted edges [(1, 2, 4.7), (2, 3, 8.2), (3, 4, 5.1)], how can you write the graph's weighted edge list to a file using NetworkX?
### Response:
import networkx as nx

# Create a graph
G = nx.Graph()
G.add_edge(1, 2, weight=4.7)
G.add_edge(2, 3, weight=8.2)
G.add_edge(3, 4, weight=5.1)

# Write the weighted edge list to a file.
nx.write_weighted_edgelist(G, 'weighted.edgelist', comments='#', delimiter=' ', encoding='utf-8')
<|EOT|>
