0

what is a better replacement for lambda x, y: x | y in form of operator.x

background: I'm trying to form django queries dynamically, for which I have created something like queries=[Q(**{query_key: phrase}) for query_key in query_keys] where query_keys is dynamically gerarated list of string which represents django query e.g. id__icontains

Pramod Jangam
  • 316
  • 3
  • 10
  • For background for everyone else, Django does OR queries using q objects and pipes akin to `Q(...) | Q(...)` and the op wants to join their list together with pipes – Sayse Jul 19 '21 at 07:31
  • I should have headed to https://docs.python.org/3/library/operator.html before stackoverflow. `operator.or_` is working for me. – Pramod Jangam Jul 19 '21 at 07:40
  • See the duplicate, there is also `Q.OR` – Sayse Jul 19 '21 at 07:41

1 Answers1

0

As shown in https://docs.python.org/3/library/operator.html#mapping-operators-to-functions, the function corresponding to the | operator is called or_.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65