Python List To Bitwise Operations
Is there a way to take a list of django query expresses (e.g. Q(first_name='Jordan'), where Q is django.db.models.Q) and bitwise OR them together? In other words, I have something
Solution 1:
You probably want
importoperator
from functools import reduce # Python 3
search_params = reduce(operator.or_, search_params, Q())
This will place a bit-wise or (|
) between all the items in search_params
, starting with an empty condition Q()
.
Post a Comment for "Python List To Bitwise Operations"