Favor list as Set over list.unique().
.unique() will maintain the order of the first occurrence at the cost of O(n²) complexity. as Set will give you the unique combinations in O(n) complexity.
If possible, return the distinct combinations directly from the database query.