mohsum
BAN USERdef bin_search(l,itm):
if len(l)== 0:
return False
else:
mid = len(l)//2
if l[mid] == itm:
return True
else:
if itm < l[mid]:
return(bin_search(l[:mid], itm))
else:
return(bin_search(l[mid+1:], itm))
tlist = [ -9, -1,0, 1, 2, 8,9, 13, 17, 19, 32, 42]
print(bin_search(tlist,8))
print(bin_search(tlist,0))
print(bin_search(tlist,29))
def least_of_k_elem():
l1 = [1, 13, 50, 184, 187, 239, 245, 262, 326, 391, 428]
l2 = [10, 74, 130, 151, 239, 336, 457, 494,517, 529, 544,]
k = int(input())
a = []
if (len(l1) and len(l2))< k:
print("enter the valid range of k")
else:
while k > 0:
if l1[0]<l2[0]:
a.append(l1[0])
l1.pop(0)
else:
a.append(l2[0])
l2.pop(0)
k -=1
print(a)
def sort_k_elem():
l1 = [1, 13, 50, 184, 187, 239, 245, 262, 326, 391, 428]
l2 = [10, 74, 130, 151, 239, 336, 457, 494,517, 529, 544,]
k = int(input())
a = []
if (len(l1) and len(l2))< k:
print("enter the valid range of k")
else:
while k > 0:
if l1[0]<l2[0]:
a.append(l1[0])
l1.pop(0)
else:
a.append(l2[0])
l2.pop(0)
k -=1
print(a)
- mohsum October 27, 2018