<｜begin▁of▁sentence｜>### Instruction:
Certainly! Let's put this in a business context:

Imagine you're a business consultant analyzing the logistics network of a client company. The company's distribution system can be visualized as a graph with various distribution centers (nodes) and the transportation routes between them (edges). You have collected data on the transportation routes which includes the nodes connected and the cost associated with each route, formatted as follows: [('A', 'B', 1), ('B', 'C', 2), ('A', 'C', 3), ('C', 'D', 4), ('B', 'D', 5)].

The client is interested in examining all of the potential distribution network configurations, essentially all spanning trees of the graph, which cover all nodes with the least amount of redundancy. They are especially keen on understanding these configurations in the order of their total associated costs, from the most cost-effective (increasing cost) to the most expensive (decreasing cost).

Your task as the consultant would be to utilize NetworkX or a similar tool to generate a list of all possible spanning trees. This analysis will provide the client with insights into optimizing their distribution network for both cost efficiency and reliability. Can you reorganize this data and approach the analysis to prioritize the spanning trees by total transportation cost, both in ascending and descending order?
### Response:
import networkx as nx

# Create a weighted undirected graph
G = nx.Graph()
G.add_weighted_edges_from(
    [('A', 'B', 1), ('B', 'C', 2), ('A', 'C', 3), ('C', 'D', 4), ('B', 'D', 5)]
)

# Iterate over all spanning trees in increasing cost
for tree in nx.algorithms.tree.mst.spanning_tree_iterator(G, weight='weight', minimum=True):
    print(tree.edges(data=True))

# Iterate over all spanning trees in decreasing cost
for tree in nx.algorithms.tree.mst.spanning_tree_iterator(G, weight='weight', minimum=False):
    print(tree.edges(data=True))
<|EOT|>
