When you set set2= set11, you are making them refer to the same dict object, so when you modify one of them, all references associated with that object reflect the current state of the object. So don’t use the assignment operator to copy the set instead use the copy() method or set() constructor.