[Python-Dev] Efficient set complement and operation on large/infinite sets. (original) (raw)
Terry Jones terry at jon.es
Fri May 12 01:33:10 CEST 2006
- Previous message: [Python-Dev] Efficient set complement and operation on large/infinite sets.
- Next message: [Python-Dev] [Python-3000] Questions on optional type annotations
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
A quick followup to my own posting:
I meant to say something about implementing rand() and pop(). I'd either add another optional function argument to the constructor. It would return a random element from the universe. Then for rand() and pop(), you'd call until it (hopefully!) returned something not excluded. Or, do something non-random, like return a random (non-excluded) integer. Or, just raise an exception.
I think I prefer the extra argument approach, where the docs state clearly that you can expect to wait longer and longer for random elements as you empty a finite inverted set. I prefer this approach because getting a random element from a set is something you really should be able to do. Just raising an exception is the cleanest and clearest choice.
One thing I certainly would not consider is trying to mess around with the excluded set (which may in any case be empty) to figure out a suitable return type.
And yes, I agree in advance, adding 5 new optional arguments to the set() constructor isn't pretty. Is the added functionality is worth it?
Terry
- Previous message: [Python-Dev] Efficient set complement and operation on large/infinite sets.
- Next message: [Python-Dev] [Python-3000] Questions on optional type annotations
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]