I have a sorted list like this
s = [1 , 4 ,6 , 9 ,10 ]
I want to know if either a number is present in the list or if it is present in between two numbers. If it is present in between two numbers, I want to print them out.
Right now my code looks like this
for x in s:
if b == x: \\ b is the number
print b
elif b > x and b < s[s.index(x) + 1] and s.index(x) < len(s):
print b , s[s.index(x) + 1]
Is there a better way to do so?
bisect module does exactly that: