<｜begin▁of▁sentence｜>### Instruction:
Given a graph with weighted edges [('A', 'B', 4.7), ('B', 'C', 8.2)], how can you write this graph to a weighted edgelist file using NetworkX, including custom comments, delimiter, and file encoding?
### Response:
import networkx as nx

# Create a graph
G = nx.Graph()
# Add a weighted edge
G.add_edge('A', 'B', weight=4.7)
G.add_edge('B', 'C', weight=8.2)

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