<｜begin▁of▁sentence｜>### Instruction:
Given a list of node names, how can you generate and retrieve unique IDs for each node, ensuring that each node gets a consistent ID even if requested multiple times?
### Response:
```python
from networkx.utils import UniqueIdGenerator

# Initialize the UniqueIdGenerator
id_gen = UniqueIdGenerator()

# Retrieve or create unique ID for an item
item = 'node1'
unique_id = id_gen[item]
print(f'Unique ID for {item}: {unique_id}')

# Retrieve or create unique IDs for multiple items
items = ['node2', 'node3', 'node1'] # 'node1' is already assigned
for item in items:
    print(f'Unique ID for {item}: {id_gen[item]}')
```
<|EOT|>
