Skip to content
Advertisement

Python LINQ like methods

As new to Python i really miss LINQ methods. I’ve found this and this questions, which helped me a lot to understand how Python enumerables and generators work.

But sill, I want to use good old methods like Select, SelectMany, First, Last, Group, Distinct and so on.

I understand, that all cases can be handled by generator and/or for expressions, but it decreases readability of code.

Advertisement

Answer

Eventually I’ve mock almost all Linq methods and made a proper wrapper, so you can chain methods.

It supports

any, all, first, first_or_none, last, last_or_none, to_list, to_dictionary, where, distinct, group_by, order_by, take, skip, select, select_many, foreach, concat, concat_item, except_for, intersect

Usage examples

JavaScript

Source code

JavaScript

As you can see, some of this cases are easily handled by python, while some of them are not. Take a piece of .NET to Python.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement