Linq to Python
digitig at gmail.com
Mon Oct 27 17:55:00 CET 2008
2008/9/24 Duncan Booth <duncan.booth at invalid.invalid>:
> Python still wins hands down on this example both in verbosity and
But AFAICS, the Python version you give creates a temporary. One of
the advantages cited for LINQs functional programming paradigm is that
it specifies what is wanted at a higher level, so the compiler can
decide whether to create temporaries, and can also decide whether to
farm the thing off to multiple processors -- harder if you've
specified in detail /how/ to do the job. Not an issue for little jobs,
but certainly an issue for, for example, a friend who had a daily
database job to do that took over 24 hours to run.
> I haven't yet had occasion to use LINQ in anger yet, so I have no idea
> whether its an idea to love or to hate. I do think it is good that C# has
> effectively sprouted list comprehensions (not to mention anonymous types
> and type inferencing) and I expect there may be some aspects worth looking
> at for Python but I think they are more likely to lead to itertools
> functions than extensions to syntax.
Yes, looking at what LINQ adds to C# (according to
- Implicitly typed variables: Python already has.
- Object and collection initialisers: Not sure whether Python can do
this directly, but it can certainly emulate it with a dictionary.
- Anonymous types: Not sure whether Python can do this directly, but
it can certainly emulate it with a dictionary.
- Extension methods: Python already has.
- Lambda expressions: Python already has.
- Auto-Implemented properties: No, but that's just syntactic sugar to
make declarations more compact.
So all of the language elements that are needed for LINQ are already
in Python; a library should do the trick.
More information about the Python-list