# Inverting a dictionary

fruit_to_colour = {
    'banana': 'yellow',
    'cherry': 'red',
    'orange': 'orange',
    'pear': 'green',
    'peach': 'orange',
    'plum': 'purple',
    'pomegranate': 'red',
    'strawberry': 'red'}

# We're going to invert fruit_to_colour.
# This means we are going to make set the keys to be the colours
# of fruit_to_colour, and the values to be a list of fruits
# with that colour.
# for example: colour_to_fruit = { 'orange': ['orange', 'peach']}

colour_to_fruit = {}
#for fruit in fruit_to_colour:
    #colour = fruit_to_colour[fruit]
    #colour_to_fruit[colour] = fruit
    
for fruit in fruit_to_colour:  
    colour = fruit_to_colour[fruit]
    
    # If colour is not already a key in the accumulator of fruits,
    # add the key with the fruit value in a new list
    if not colour in colour_to_fruit:
        colour_to_fruit[colour] = [fruit]
    # Otherwise, append ruit to the existing list
    else:
        colour_to_fruit[colour].append(fruit)
    


print(colour_to_fruit)
print(colour_to_fruit['orange'])
print(colour_to_fruit['orange'][1])