loading...

re: Intersection, union and difference of Sets in Python. VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Hi Sebastian, nice article! Sets are great and "set comprehensions" are so cool. I have a tip for construction: >>> a = {1, 2, 3} >&...
 

Hi, thanks a lot for the comment.

As stated in my post, yes, we can use curly braces to avoid the intermediate collection, but I think, unless performance is an issue, we should use the constructor, as curly braces are also used for dictionaries.

Curly braces may be used too, which will avoid creating an intermediate list, but as they are also used for dictionaries, you can not create an empty set with curly braces. Also, someone can get confused, so I avoid them and stick to the constructor.

On the other hand, I did not know about those operators, so thanks a lot for bringing them up, although I agree with you, the usage of the functions is more readable.

Again, thanks for your coment.

Regards!

code of conduct - report abuse