Lets say i have a dictionary:
favorittForfattere={'Per':'Christie','Kari':'Ibsen', \
'Liv':'Rowling','Ola':'Ibsen', \
'Anne':'Allende', 'Jens':'Christie'}
With this dictionary i want to create a function where i get the keys and values from that dictionary, and then append them in to a new dictionary which gets created during the function. the values of the previous dictionary will be keys in the new dictionary. the keys from the previous dictionary will be values in the new dictionary.
The expeted outcome would be this
{'Christie': ['Per', 'Jens'], 'Ibsen': ['Kari', 'Ola'], 'Rowling': ['Liv'], 'Allende': ['Anne']}
This is my code so far
def fans(favorittForfattere):
nyFortegnelse = {}
for keys, values in favorittForfattere.items():
nyFortegnelse.update({values:keys})
print(nyFortegnelse)
How would i solve this problem?
This is the whole code snip so it makes sence
favorittForfattere={'Per':'Christie','Kari':'Ibsen', \
'Liv':'Rowling','Ola':'Ibsen', \
'Anne':'Allende', 'Jens':'Christie'}
def fans(favorittForfattere):
nyFortegnelse = {}
for keys, values in favorittForfattere.items():
nyFortegnelse.update({values:keys})
print(nyFortegnelse)
fans(favorittForfattere)