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
Make bisect.* functions accept an optional compare function #41873
Comments
The usability of bisect.bisect_right, bisect.bisect_left, Here is my use case: I have a sorted list of reversed words Issue #1: Now I cannot use simply a list of tuples Issue #2: When a word is not found in the list, I'd from bisect import *
less_than = lambda x,y: x[:3]<y[:3]
lp = bisect_left(word_list, given_rev_word, lt=less_than)
rp = bisect_right(word_list, given_rev_word, lt=less_than)
# return the union of flag_list[lp:rp] An example (given_rev_word = 'abcpqr'): Currently, the first search could be replaced with Rolling my own class that stores a word and its flags, I hope that I expressed myself clearly enough. If not, let |
Logged In: YES A few thoughts:
Will leave this request open as it may yet be a good idea. Also, I'm looking at a more general purpose solution that dwordlist = map(ComparisonDecorator(lambda x: x[:3]),
wordlist)
lp = bisect_left(dwordlist, given_rev_word)
rp = bisect_right(dwordlist, given_rev_word) |
Logged In: YES In a similar vein, I'd like to see that a |
Logged In: YES Overall, I'm -1 on this RFE. The comparison to nsmallest() and nlargest() is inaccurate. Likewise, with this request, the key function calls get |
Logged In: YES
Which is exactly *why* I'm suggesting the key argument: to Since that sounds counter-intuitive, let me explain: one |
Logged In: YES The whole purpose of the key= argument was to avoid having Closing this because:
|
This really is annoying. If sort() accepts different comparison functions, so should bisect & co. It makes things that should be easy, very hard. If you are writting threaded programs, you know that functions passed to sort and bisect have to behave properly. |
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: