On Sat, Nov 7, 2015 at 4:34 PM, Milan Bouchet-Valat <nalimi...@club.fr> wrote:
> Le samedi 07 novembre 2015 à 06:37 -0800, Michele Zaffalon a écrit : > > What is the best way of telling whether an element `x` is present in > > a sorted list `a`? > > > > Using `searchsortedlist`, I also need to check that the element is > > present in the list. This is what I do > > > > function isinsortedlist(a, x) > > n = searchsortedfirst(a, x) > > n <= length(a) && a[n] == x > > end > > > > Shouldn't `searchsortedlist` return also a bool to tell whether the > > element is already in the list? > Just use searchsorted(), which (as the docs say) "Returns an empty > range located at the insertion point if a does not contain values equal > to x". > Now that you mention it, it is obvious. Thank you. > > > Regards > > > Thank you, > > michele >