def function(partition,value): for i in range(len(partition)): if partition[i]<value and partition[i+1]>value: print [partition[i],partition[i+1]] partition = [0, 3, 7, 12, 18, 23, 27,5,10] value=9 function(partition,value)