From 23 to 31 as well last program, how the output is 4 2 ???? Full code: https://code.sololearn.com/cd7UARAhrx6c/?ref=app
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).
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.
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 is 1 a is 2 a is 4 a is 5 That's all. There is no "a(4), a(6), a(3)...". a looks at index/position 3 and returns the value 5. `left_bisect(a, 3)` uses value 3 and returns the index/position 2.
Mozzy I think a start from where a finished. a finished at 4, a=[1,2,4,5] Now, a is 4 a is 5 a is 1 And finally a is 2.😃 Does it the right method?
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 means the first value, which is 1. Read more carefully Mozzy's comment until you understand...
How do I generate a list with <N> unique elements randomly selected from another (already existing) list?
Given three integer matrices A(m*n),B(m*n) and C(m*n) . Print the one with more zero elements. beside code
I'm coding this for hours & can't make the value of the 5 random numbers round off to 2 decimal places like in the examples
Overloading + operator
( NEED HELP ) Halloween candy