Maybe there's some subtlety that I do not get, but unless I am mistaken, you only have to check whether the elements are between the min
and max
from a
. This is independent of whether the elements in a
are sorted, or whether the values from b
have to be between consecutive values from a
. As long as they are between the min
and max
, there has to be a "segment" in a
those values are in.
>>> a = [1, 4, 12]
>>> b = [2, 13]
>>> n, m = min(a), max(a)
>>> [n < x < m for x in b]
[True, False]
That is, of course, only if (a) you do not need which numbers they are in between, and (b) if not all values in b
have to be in the same interval.
If you think I missed something, please comment.