This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients rhettinger, terry.reedy
Date 2016-09-10.22:22:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1473546124.61.0.846799872363.issue28071@psf.upfronthosting.co.za>
In-reply-to
Content
Proposal from SO: in the iteration loop for 'myset.difference(iterable)', add equivalent of "if not myset: break'.
https://stackoverflow.com/questions/39378043/why-does-pythons-set-difference-method-take-time-with-an-empty-set

In the toy example for testing that this is currently not so, myset starts empty, but it was noted by the OP that a more realistic example would be that myset becomes empty after deletions.

Postulated reasons why not to do this (as opposed to why it has not been done yet ;-):

1) averaged over all uses, the time saved not iterating would be less than the time spent testing emptyness.

2) an implicit guarantee to complete the iteration for possible side-effects.

One answer notes that myset.difference(anotherset) is special-cased and faster than the equivalent non-set iterable.

I searched the tracker for 'empty set difference' and got no hits.  If I remember, I will post any disposition of this issue back to SO.
History
Date User Action Args
2016-09-10 22:22:04terry.reedysetrecipients: + terry.reedy, rhettinger
2016-09-10 22:22:04terry.reedysetmessageid: <1473546124.61.0.846799872363.issue28071@psf.upfronthosting.co.za>
2016-09-10 22:22:04terry.reedylinkissue28071 messages
2016-09-10 22:22:04terry.reedycreate