Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import operator
- from bisect import bisect_left
- def index(a, x):
- 'Locate the leftmost value exactly equal to x'
- i = bisect_left(a, x)
- if i != len(a) and a[i] == x:
- return i
- raise ValueError
- def BinSearchLeft(li, x):
- i = 0
- j = len(li)-1
- m = int(j/2)
- while li[m][0] > x and i < j:
- if x > li[m][0]:
- i = m+1
- else:
- j = m-1
- m = int((i+j)/2)
- if i > j:
- return 'Нет такого'
- else:
- return m
- a = [[1,2,3,4,5],
- [11,12,13,14,15],
- [21,22,23,24,25],
- [31,32,33,34,35],
- [41,42,43,44,45]]
- x = 24
- row = BinSearchLeft(a, x)
- print(row)
- col = index(a[row], x)
- print(col)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement