2. Transform this list into a dictionary.
Tips: Use the dict() function.
3. Add ‘rectangle’ to the dictionary with a value of ‘green’.
4. Remove the ‘circle’ key-value pair.
5. Remove the ‘triangle’ key-value pair using another method.
6. Find a way to turn the dictionary into a list of tuples again.
Right Answer:
# Step 1
shapes = [('square', 'blue'), ('triangle', 'red'), ('circle', 'yellow')]
# Step 2
shapes_dict = dict(shapes)
# Step 3
shapes_dict['rectangle'] = 'green'
# Step 4
shapes_dict.pop('circle')
# Step 5
del shapes_dict['triangle']
# Step 6
shapes_list = list(shapes_dict.items())
print(shapes_list)
# Output: [('square', 'blue'), ('rectangle', 'green')]