Deleting a Key and its occurrence in other key's Value in python dictionary -
suppose have dictionary
mydict={0: set([1]),1: set([0, 2]),2: set([1, 3]),3: set([2])}
and want delete 1 dictionary ,that means key "1" , every occurence of 1 in sets of value of other key .for e.g deleting 1 make dictionary
mydict={0: set([]),2: set([ 3]),3: set([2])}
i trying achieve not able .thanks in advance
del mydict[item] key, value in mydict.items(): if item in value: mydict[key] = value.difference(set([item]))
you can use this. first remove item
dictionary, remove occurances of values using set difference.
Comments
Post a Comment