Take this simple C # LINQ query and imagine that 'db.Numbers' is a single column SQL table, Number:
var result = from n to db.Numbers where n.Number <5 select n.Number;
This will work very efficiently in C # because it generates an SQL query, for example, "select Number from Numbers where Number <5". What he does not do is to select all the numbers from the database and then filter them in C #, as it might seem at first.
Python supports a similar syntax:
result = [n.Number for n in numbers if n.Number <5]
But this "if" clause here performs filtering on the client side, and not on the server side, which is much less efficient.
Is there something as effective as LINQ in Python? (I am currently evaluating Python vs IronPython vs Boo, so an answer that works in any of these languages ββis fine.)
source share