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...
What's wrong? :(
Why won't my image display
I have made a calculator in which my % (Percentage) not work correctly for 100%50 or 100%20.
How the answer is 50?
Number of Ones ( C++ ) question!