<｜begin▁of▁sentence｜>### Instruction:
Given a MultiGraph where one edge connects node 1 to itself (selfloop), and another edge connects node 1 to node 2, how can you retrieve a list of all selfloop edges, optionally with associated edge data and keys?
### Response:
import networkx as nx

# Create a MultiGraph
G = nx.MultiGraph()

# Add selfloop edge and another edge
ekey1 = G.add_edge(1, 1)
ekey2 = G.add_edge(1, 2)

# Get a list of all selfloop edges without data
selfloops_without_data = list(nx.selfloop_edges(G))
print('Selfloop edges without data:', selfloops_without_data)

# Get a list of all selfloop edges with data
selfloops_with_data = list(nx.selfloop_edges(G, data=True))
print('Selfloop edges with data:', selfloops_with_data)

# Get a list of all selfloop edges with keys
selfloops_with_keys = list(nx.selfloop_edges(G, keys=True))
print('Selfloop edges with keys:', selfloops_with_keys)

# Get a list of all selfloop edges with keys and data
selfloops_with_keys_and_data = list(nx.selfloop_edges(G, keys=True, data=True))
print('Selfloop edges with keys and data:', selfloops_with_keys_and_data)
<|EOT|>
