i2
Joined 16 years ago
Karma
17
Submissions
6
Member since
Jul 24
Joined 16 years ago
> [10, 1, 5, 1, 10, 10, 1, 5, 5, 5, 10].sort(byNum)
> [10, 10, 5, 1, 10, 1, 1, 5, 5, 5, 10]
The right way is > function byNum(a, b) { return a - b; } >>> ZERO = lambda f: lambda x: x
>>> FIVE = lambda f: lambda x: f(f(f(f(f(x)))))
>>> to_int = lambda f: f(lambda x: x+1)(0)
... etc. collection = Transaction.search(
order_id__starts_with='a2d',
customer_website__ends_with='.com',
billing__first_name__exact='John',
status__in=[
Transaction.Status.Authorized,
Transaction.Status.Settled
],
amount__between=("10.00", "20.00")
)
the implementation could look like this: def search(**kwargs):
for arg, value in kwargs.items():
action = arg.split('__')
attr = getattr(self, action[0])
if len(action) == 2:
method = getattr(attr, action[1])
method(value)
etc.
.....
EDIT: removed unneeded quotes, thanks for correction, postfuturist