You can also use list.set_symmetric_difference function. It computes the difference between two lists as a sets https://docs.pola.rs/api/python/stable/reference/expressions/api/polars.Expr.list.set_symmetric_difference.html#polars.Expr.list.set_symmetric_difference
The benefit is that the elements order inside compared lists can be arbitary
df = polars.DataFrame(dict(j=[
[1,4,7],
[2,5,8],
[3,6,9],
]))
df.filter(
pl.col("j").list.set_symmetric_difference(
pl.lit([2, 5, 8])
).list.len() == 0
)
shape: (1, 1)
┌───────────┐
│ j │
│ --- │
│ list[i64] │
╞═══════════╡
│ [2, 5, 8] │
└───────────┘
or
df.filter(
pl.col("j").list.set_symmetric_difference(
pl.lit([8, 5, 2])
).list.len() == 0
)
shape: (1, 1)
┌───────────┐
│ j │
│ --- │
│ list[i64] │
╞═══════════╡
│ [2, 5, 8] │
└───────────┘