New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a get() method to sets #42315
Comments
Hi, I would like to propose a new method for the builtin Right now the simplest way to do that is : There are two problems with this:
Although the first problem is rather minor (but There is a way to avoid the second problem : So for the bottom line: it would be in some cases very The implementation would probably not be very What do you think ? Regards Antoine. |
Logged In: YES We've looked at a choose() method a couple of times and Also, a choose method() would need to raise a KeyError if Put the two together and the idea loses any charm. Also, for mutable sets, a better approach is to pop() I'm not too concerned about atomicity. For one, that is I do understand that basic motivation (I have a set, now how BTW, please post your use case (in a condensed form that |
Logged In: YES Hi, Thanks for the detailed reply. So, atomicity cannot be As for the first objection: my set is mutated in the loop in As for the use case : I'm writing a small cooperative The main loop is in the Switcher.run() method towards the As you see, I actually do a "for" on the set, but I always |
Logged In: YES This does look like pop might be a better choice. When choosing a ready object, you pop it to unready When choosing a waiting ready thread, either the thread |
Logged In: YES
That's not exactly my semantics (objects remain ready until Thanks for the very prompt answers, btw :) |
Logged In: YES _My_ use case for something like this is applying a series of constraints |
Logged In: YES Exploratory questions: Michael, if you know there is only one element in a set, do
Antoine, yes a pop()/add() combination is efficient. IMO, Question for Antoine: Have you ever had this need with Question for everyone: Since choose() would not be a Question for everyone: Is there any known application for For applications other than Michael's, we won't know the Rather than a method just for sets, is it a more appropriate def getfirst(it):
for elem in it:
return elem
raise ValueError('iterator is empty') A function like this would work with almost anything: |
Logged In: YES Hi again,
Ok, thanks.
Small correction: the pop() is atomic, but the pop/add
I think I had it for a dict sometime. For lists and tuples,
The variable to which you apply the method call could
I don't think so indeed. (it would be the case if the API
First, sometimes you know the set is non-empty without
Well, I thought global builtin functions were less favoured (*) if there was a base type "iterable" with the generic Anyway, if the concern with builtin types is to avoid |
Logged In: YES Mmm, the "v, = s" approach hadn't occurred to me and it seems ok. The |
Logged In: YES
[mwh]
Those two answers suggest this RFE is unnecessary. If you |
Logged In: YES For the record, here are some research results. Java's set objects do not have a choose() method: In contrast, SETL does provide a function for extracting Core Perl only has arrays and hashes. Mathematica provides set operations on lists (union, |
Logged In: YES
Well, closing the request is fine for me. Although I don't |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: