<｜begin▁of▁sentence｜>### Instruction:
Given a graph with edge set [(1, 2), (2, 3), (3, 4), (4, 1)], how do you find a 1-factor of the graph using NetworkX's k_factor function? A 1-factor is a spanning 1-regular subgraph, meaning each node has exactly one connected edge in the subgraph.
### Response:
import networkx as nx

# Create a graph
G = nx.Graph()
G.add_edges_from([(1, 2), (2, 3), (3, 4), (4, 1)])

# Compute a 1-factor of the graph G
k = 1
G2 = nx.k_factor(G, k=k)

# Print the edges of the 1-factor
print('1-factor edges:', list(G2.edges()))
<|EOT|>
