New answers tagged

2

I'm going to demonstrate Nearest, even though NearestFunction is about 10-20 times slower than Lookup. On the other hand Nearest is faster at creating the underlying data structure than AssociationMap/PositionIndex. The use of Lookup seems clearer than this indirect use of Nearest, so the interest may be only academic. list = RandomInteger[10^9, 10^6]; ...


4

MemberQ's operator form seems to be useful for searching for the same value in different lists. If you need to search for different values in the same list many times, I would build an association that has the list elements as keys, and then use Lookup. For example, list = RandomInteger[10, 10] (* {3, 8, 9, 3, 8, 3, 5, 8, 9, 5} *) asc = AssociationMap[...


1

Using george2079's suggestion, the code can be tweaked to ExactExpressionQ[expr_] := FreeQ[expr, _Real|_Complex?InexactNumberQ, {-1}] for better performance.



Top 50 recent answers are included