human
Search an element in given N ranges | Function to return the index of the range in which K lies and uses binary search.
Binary search.
Find the mid element.
If element is found.
Check in first half.
Check in second half.
Not found.
Driver code"
How can the above be solved in Python?

Give me a code to search an element in given N ranges and the other steps required?
assistant
#Here is code to search an element in given N ranges and the other steps required.
 def findNumber ( a , n , K ) :
	low = 0
	high = n - 1
	while ( low <= high ) :
		mid = ( low + high ) >> 1
		if ( K >= a [ mid ] [ 0 ] and K <= a [ mid ] [ 1 ] ) :
			return mid
		elif ( K < a [ mid ] [ 0 ] ) :
			high = mid - 1
		else :
			low = mid + 1
	return - 1
a = [ [ 1 , 3 ] , [ 4 , 7 ] , [ 8 , 11 ] ]
n = len ( a )
k = 6
index = findNumber ( a , n , k )
if ( index != - 1 ) :
	print ( index )
else :
	print ( - 1 )