<｜begin▁of▁sentence｜>### Instruction:
Given a graph with nodes 1, 2, and 3 having a node attribute 'color' set to 'red', and a node 4 without this attribute, how can one retrieve the 'color' attribute for all nodes, defaulting to 'yellow' for nodes without an explicitly set 'color' attribute?
### Response:
import networkx as nx

# Create a graph
G = nx.Graph()
# Add nodes with the attribute 'color'
G.add_nodes_from([1, 2, 3], color='red')
# Access node attributes
color = nx.get_node_attributes(G, 'color')
# Print the color of node 1
print(color[1])
# Add a node without the color attribute
G.add_node(4)
# Access node attributes with a default value
color = nx.get_node_attributes(G, 'color', default='yellow')
# Print the default color of node 4
print(color[4])
<|EOT|>
