I am looking at some Web2py code.
The variable tokens is some kind of a list of strings. To be more precise, it is defined as tokens = form.vars.name.split() where form.vars.name is a string.
My question deals with the following instruction :
query = reduce(lambda a,b:a&b,[User.first_name.contains(k)|User.last_name.contains(k) for k in tokens])
Here are my questions :
-
I know
lambda a,b:a&bdefines a function ofaandb. What isa&b? -
Is the
containsmethod ofUser.first_namespecific to Web2py ? Or does it exist in standard Python ? -
What is this
|operator inUser.first_name.contains(k)|User.last_name.contains(k)? -
What does the
reducefunction do ?
&and|are not bitwise and/or here, but are used to build a special object that represents a database query! They correspond toANDandORin SQL statements