any optimzation suggestion for parsing huge lists in python

'''
function of code
check for closest greatest element in list a for every element of list b
if elemet found it removes that element from orignal list
so the next element can be compared
ex: lista=[2,3,4] list b=[0,0,7] =>2,3,-1
if no element found it return -1
i am getting tle for some test cases using this approch

''' py
def greaterButClosest (list, find):
found = -1
for idx in range (len(list)):
if list[idx] > find:
if found == -1:
found = idx
else:
if list[idx] < list[found]:
found = idx

if found == -1:
    return -99999
return list[found]

a=list(map(int,"3 6 7 5 3 5 6 2 9 1 ".split()))
a.sort()
b=list(map(int,"2 7 0 9 3 6 0 6 2 6 ".split()))
for tst in b:
vaar=greaterButClosest(a,tst)
if vaar in a:
del a[a.index(vaar)]
print(10-len(a))
'''

Comments (0)