the "bisect" subcommand of Git or the "bisect" module of Python
Questions tagged [bisect]
105 questions
0
votes
1 answer
Python Lookup - Mapping Dynamic Ranges (fast)
This is an extension to a question I posted earlier: Python Sum lookup dynamic array table with df column
I'm currently investigating a way to efficiently map a decision variable to a dataframe. The main DF and the lookup table will be dynamic in…

Mikal Fischer
- 21
- 4
0
votes
0 answers
Fast way to find elements in list of hashed tuples in python
I am trying to solve the following problem efficiently:
Given the following class
class Obj:
t1: int
t2: int
def __hash__(self):
# compute hash on frozenset to make sure switching the to and from id has no effect
return…

DUWUDA
- 342
- 5
- 13
0
votes
2 answers
using bisect with tuples in python
I am trying to understand the use of bisect function in the python's bisect module and how to use it with tuples. I have seen that it takes a list and a value to find the index to place the value. In my case the value is a tuple. This is from…

nsingh
- 61
- 1
- 5
0
votes
1 answer
Python bisect with value x is an array of length 1
I'm trying to understand this code:
i = bisect.bisect(self.A, [id + 1]) - 1
Here, the developer passed [id + 1] in the bisect() as x (the target value). In both Python docs and its source code for bisect, I don't see anywhere mentioned that x can…

Viet
- 6,513
- 12
- 42
- 74
0
votes
1 answer
Nearest timestamp in python
I have a list of timestamps and a key timestamp to find the nearest one, both are in the format '2019-11-22T11:37:52.338Z'
I have tried this solution Python - Locating the closest timestamp but since my timestamps are in string leads me with an…

iamkk
- 135
- 1
- 16
0
votes
4 answers
how to see if there is a value in a list that is between two values from another list
I have two lists
a = [1, 4, 12]
b = [2, 13]
I want to know if values in list b are between two values in list a
So, in this case, 2 will fall between 1 and 4. 13 will not fall between any numbers.
I have tried bisect function, but I couldn't get it…

Yun Tae Hwang
- 1,249
- 3
- 18
- 30
0
votes
1 answer
Python, why is bisect.insort much faster than my linkedlist
So I am trying to keep a list in order at all times. So whenever new data comes in, I will insert this to the 'sorted list'.
Question, why is bisect.insort much faster than my linked list implementation. I know bisect search takes O(logn), but due…

user1179317
- 2,693
- 3
- 34
- 62
0
votes
0 answers
Is it possible to do a bisect search in Github
Background
I've been working in Github lately. But with all of this Travis-ci and stuff, I've been trying to debug code like crazy. I know about the git bisect git command. And since I've been trying to stuff on Github lately, I though, "Hmm, does…

theX
- 1,008
- 7
- 22
0
votes
1 answer
Vectorize step-wise function for column in pandas dataframe
I have a slightly complex function that assigns a quality level to given data by a pre-defined step-wise logic (dependent on fixed borders and also on relative borders based on the real value). The function 'get_quality()' below does this for each…

Andi
- 778
- 7
- 15
0
votes
0 answers
How Do I Use Bisect to Classify a Value?
I have various heights (z) that I want to classify into different layers. Looking online it looks like the bisect_left function is a good way of finding where in a list a value should appear. I have defined the name of each layer to be the position…

Eli Rees
- 178
- 2
- 14
0
votes
1 answer
How can bisect_right() be 4x slower than insort_right()?
I'm trying to optimize a solution that times out on a competitive programming website. I started using cProfile and it appears to show bisect_right() requiring 4x as much time as insort_right(). This is a profiling run on input list with over 40k…

Andrew Lamoureux
- 70
- 7
0
votes
1 answer
Find zeroes of function with simpy.optimize.bisect, with a complex function
I'm a student of mechanical engineering, and this is the first year I've met with the Python environment, or the distribution of it Anaconda.
I was given a task to find the zeroes of this function:
⋅sin()cos()+⋅cos()sin()2−⋅cos()−ℎ⋅sin()=0
With…

Wyvern
- 11
- 2
0
votes
1 answer
Try-Except Clause Ignored in Linear List Insertion Algorithm Using Bisect Module (Python)
I'm trying to insert an element into a linear list using input() with bisect() and insort() functions of the bisect module in Python 3.7. To accept only integer inputs, I tried adding a try-except clause (as suggested in an answer to: Making a…

Kartik
- 33
- 1
- 7
0
votes
0 answers
assign value based on timestamps
I got two dataframes, the first one is like
data = [
[11,'a',1],
[16,'b',2],
[15,'a',3],
[19,'b',4]
]
data=pd.DataFrame(data)
and the second one is like
find=[
[4,'a'],
[11,'b'],
[11,'a'],
[16,'b'],
…
0
votes
1 answer
Using bisect in a list of tuples with checking both element of tuple?
I read this question about how to use bisect on a list of tuples and only compare the first value of tuple. It works, but how can I compare two value? if index of x < index of y and y[0] <= x[0] or y[1] <= x[1], bisect.bisect_left return…

jacobcan118
- 7,797
- 12
- 50
- 95