<｜begin▁of▁sentence｜>### Instruction:
Given a priority queue with elements 'red', 'blue', 'green' with priorities 665, 470, 550 respectively, how do you perform the following operations using MappedQueue from NetworkX: remove the 'red' element, update the priority of 'green' to 400 and change its key to 'violet', insert a new element 'indigo' with priority 425, and then extract all elements in sorted priority order?
### Response:
import networkx as nx
from networkx.utils import MappedQueue

# Initialize the MappedQueue with a dictionary of elements and their priorities
colors_nm = {'red': 665, 'blue': 470, 'green': 550}
q = MappedQueue(colors_nm)

# Remove an element
q.remove('red')

# Update the priority of an element and change its key
colors_nm.update({'green': 'violet'})
q.update('green', 'violet', 400)

# Push a new element
q.push('indigo', 425)

# Extract elements from the queue in order of their priority
sorted_elements = [q.pop().element for i in range(len(q))]
print(sorted_elements)
<|EOT|>
