Search code examples
pythonpython-3.xreducers

pipe/union operator in python


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


Solution

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