The Set data structure saved me from a world of pain
sankalpjonna.com
sankalpjonna.com
len(set(mylist)) == len(mylist)
which probably loses on big O to some more clever approaches but is just fine for small n, and very readable.Other trivially answerable questions include “what’s in me but not in this other collection”, “what’s in both of us”, “what’s in exactly one of us”, ... etc.
This solution requires an extra instance of Redis in addition to a SQL db (which I assume is already in the mix), and has the potential for consistency drift.
And SQL is a very close cousin of set theory.
Given that the SQL approach is the standard one, I'd personally expect load testing to demonstrate that it didn't scale before doing something unusual.
Time and again I have found nested loops for determining whether any elements of A are missing from B.