fork download
  1. dict1 = {'1':'foo', '2':'bar', '3':'spam','4':'bar'}
  2. dict2 = {}
  3.  
  4. for k, v in dict1.iteritems():
  5. print dict2.keys(), v
  6. if v not in dict2.keys():
  7. print "adding %s to dict2" % v
  8. dict2[v] = "whatever"
  9.  
  10. else:
  11. print "Repeated: ",v
  12.  
  13. print dict2
Success #stdin #stdout 0.01s 7728KB
stdin
Standard input is empty
stdout
[] foo
adding foo to dict2
['foo'] spam
adding spam to dict2
['foo', 'spam'] bar
adding bar to dict2
['foo', 'bar', 'spam'] bar
Repeated:  bar
{'foo': 'whatever', 'bar': 'whatever', 'spam': 'whatever'}