Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepython
kokebok = {'pasta carbonara':['fløte','pasta','bacon','egg'], 'sopp -risotto':['sopp','ris','fløte'], 'pasta bolognese':['pasta','kjøttdeig','tomatsaus']}

...

Code Block
languagepython
#a
print(kokebok.get('pasta carbonara'))

#b
kokebok['kyllingsalat'] = ['kylling','tomat','agurk','salat']

#c
if 'sopp -risotto' in kokebok:
    print ('sopp -risotto finnes i kokeboken')
else:
    print ('beklager, opp sopp-risotto finnes ikke i kokeboken')

#d
del kokebok['pasta bolognese']

...

Code Block
languagepython
for rett in kokebok:
    print (rett + ' inneholder ' + str(kokebok.get(rett))) 
 
#alternativt:
for rett, innhold in kokebok.items():
    s = ''
    for el in innhold:
        s += el+', '
    print(rett,'inneholder',s[0:-2])

Oppgave 11 - Endre verdier i en dictionary

...