That's a bit biased, no? The actual comparison should be:
filtered = Q(l,{'name__contains':"k", "age__lt":20})
filtered = [x for x in l if ('k' in x['name'] and int(x['age']) < 20)]
Something like Clojure would be perfect for this. Write a macro that converts
{"name" (includes? "k"), "age" (< 20)}
{"name" #(includes? % "k"), "age" #(< % 20)}
{"name" (fn [name] (includes? name "k")), "age" (fn [age] (< age 20))}
You could serialize the patterns using EDN as a substitute for JSON.
Fun stuff.
I wrote something [similar][1] in javascript. With that it would be:
const is_k_kid = tisch.compileFunction((etc) => ({ 'name': name => name.includes('k'), 'age': age => age < 20, ...etc })); const result = input.filter(is_k_kid);
[1]: https://github.com/dgoffredo/tisch
Something like Clojure would be perfect for this. Write a macro that converts
into which is the same as Then have another macro that converts that into the pattern matching code, or maybe there's already something in the standard library.You could serialize the patterns using EDN as a substitute for JSON.
Fun stuff.
I wrote something [similar][1] in javascript. With that it would be:
Yes, "...etc" is part of the DSL.[1]: https://github.com/dgoffredo/tisch