So the question came to my mind, in a list, set or tuple if an item/ object doesn't exist then can't WeakSet be helpful ?
So what I came to learn is you can reference weakRef object in the set as long as it exists. It will be removed when the last reference is let go and it gets garbage collected. Helps for stuff like indexing other objects and allowing them to disappear when they should.
so what I make out if this there is some benefit of using WeakSet or you referred to sets only because it would be automatically garbage collected...
using WeakSet, If you put an object in there, and then the object goes out of scope, it will disappear. Because the WeakSet isn't keeping the reference count up. Here is a random example: Lets say you have a bunch of objects and you want to categorize some of them as being "good". You can put the ones you want into a WeakSet called goodSet. Now when the actual original objects get deleted, they will automatically remove themselves from the goodSet. You don't have to go and keep track of them in multiple places. But you can look at that goodSet any time you want to see if something is in there. I actually have used WeakKeyDictionary and WeakValueDictionary a lot more, for associating objects with some value. But if the object gets deleted, it will pop out of the dict automatically.