OK, but I doubt that your current solution is efficient. Isn't searchsorted more readable ? WHat do you lose by using it ?