Python: Does the set.add () function not add duplicates?

I have several tuples stored in a set, and I'm trying to add two sets of duplicates to the set through a nested loop loop, which basically iterates through another group of tuples and checks the condition in the tuple, and then adds the tuple to the set if the tuple satisfies the condition . However, some tuples are duplicated, and I notice that duplicates are not added.

+4
source share
2 answers

A set cannot contain duplicates. This is the dialing point. If you want to duplicate, consider using a list.

+12
source

Establish unordered collections of unique elements by definition, so they do not allow duplication. Please check the python documentation.

+2
source

All Articles