f={'food':'apple','book':'Gulliver','season':'spring','drink':'Coca-Cola','animal':'lion'} for x,y in f.items(): del f[x] f[y]=x print f,len(f)
Этот код действует.
А если изменить список:
f={16:3,12:2,18:4,3:0,4:1}
f={'food':'apple','book':'Gulliver','season':'spring','drink':'Coca-Cola','animal':'lion'} for x,y in f.items(): del f[x] f[y]=x print f,len(f)
f={16:3,12:2,18:4,3:0,4:1}
f={16:3,12:2,18:4,3:0,4:1}
f = {value:key for key, value in f.items()} print f, len(f)