0
Need solution
From 23 to 31 as well last program, how the output is 4 2 ???? Full code: https://code.sololearn.com/cd7UARAhrx6c/?ref=app
7 Respostas
+ 3
Please read the documentation of bisect_left.
https://docs.python.org/3/library/bisect.html
"Locate the insertion point for x in a to maintain sorted order."
So assuming you have a list with sorted values, the bisect_left function basically tells you at which position the value fits in. So given some ranges or buckets of values, it tells you in which bucket the value fits. Searching for the value 6, it determines that all 4 values of the list are smaller than that, therefore the insertion point would be index 4 (meaning the fifth value, after the last one).
+ 3
a = [1, 2, 4, 5]
`bisect.left_bisect(a, 6)` returns index value of 4 because if 6 is inserted in the list in a way that it maintains sorted order (i.e. [1, 2, 4, 5, 6]), then 6 will be at index 4 in the list.
Same logic for `bisect.left_bisect(a, 3)`. It returns 2 because if 3 is inserted in the list while maintaining sorted order (i.e. [1, 2, 3, 4, 5]), then 3 will have index of 2.
Note: No insertion actually happens, it's just an illustration to help understand how the function works. Under the hood, the function uses binary search to find the index. Consequently, the list `a` must already be sorted for the function to give correct results.
+ 3
I think you're mixing up the index operation a[i] with the `left_bisect(a, x)` function. Note the difference in brackets, arguments and return values.
a[0] is 1
a[1] is 2
a[2] is 4
a[3] is 5
That's all. There is no "a(4), a(6), a(3)...".
a[3] looks at index/position 3 and returns the value 5. `left_bisect(a, 3)` uses value 3 and returns the index/position 2.
+ 1
Mozzy I think a[3] start from where a[6] finished.
a[6] finished at 4,
a=[1,2,4,5]
Now,
a[0] is 4
a[1] is 5
a[2] is 1
And finally a[3] is 2.😃
Does it the right method?
+ 1
Tibor Santa Mozzy
Thanks for helping 💘💘
+ 1
Mustakim Rahman based on your last comment you are still not getting it.
"a" is a list.
You have values in the list, and each value has a position, that is called index. The index begins with 0 and grows by 1 for every value. You refer to the values, by putting the index in square brackets after the list name. So a[0] means the first value, which is 1.
Read more carefully Mozzy's comment until you understand...
0
Mozzy Tibor Santa
Sorry to bother that i cannot understand that part.🙄
Feeling upset brother!
a=[1,2,4,5]
If i share my thought is..
a(6) mean a(0)=1,a(1)=2,a(2)=4,a(3)=5,a(4)=1,a(5)=2,a(6)=4..
So a(6)=4.
But how a(3)=2?
Shouldn’t it 5?