Need help with linqit?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

avilum
220 Stars 10 Forks Apache License 2.0 48 Commits 0 Opened issues

Description

Extend python lists with .NET's LINQ syntax for clean and fast coding. Also known as PINQ.

Services available

!
?

Need anything else?

Contributors list

# 318,445
python3
linq
develop...
pythoni...
23 commits
# 16,847
Flask
cython
python3
gui-fra...
2 commits
# 328,381
python3
linq
pypi
msp430
1 commit
# 367,075
chromec...
chromec...
python3
linq
1 commit
# 151,470
Shell
python3
linq
develop...
1 commit

Linqit!

Extends python's list builtin with fun, robust functionality - .NET's Language Integrated Queries (Linq) and more.
Write clean code with powerful syntax.

shell script
pip install linqit
Stop using loops, complex conditions, list comperhension and filters.
Doesn't it looks better?
```python from seven_dwwarfs import Grumpy, Happy, Sleepy, Bashful, Sneezy, Dopey, Doc from linqit import List

Go ahead and fill the list with whatever you want... like a list of objects.

programmers = List() Avi = type("Avi", (), {}) elon_musk = Entrepreneur(talented=True)

Then play:

lasthotpizzaslice = ( programmers.where(lambda e: e.experience > 15) .exceptfor(elonmusk) .oftype(Avi) .take(3) # [, , ] .select(lambda avi: avi.lunch) # [, , ] .where(lambda p: p.is_hot() and p.origin != "Pizza Hut") .last() # .slices.last() # )

What do you think?

We all use multiple aggregations in our code, while multiple filters/comprehensions are not pythonic at all.
The whole idea is is to use it for nested, multiple filters/modifications :).
Some of the methods might look ridiculous for a single calls, comparing to the regular python syntax.
Here are some use cases:

Methods:

all any concat contains distinct exceptfor first getbyattr intersect last select skip take where oftype ```

Properties:

sum
min
max
avg
sorted

Deeper - Let's play with a list of people, a custom type.

import List

class Person(): def init(self, name, age): self.name = name self.age = age

def __repr__(self):
    return 'Person(name="{}", age={})'.format(self.name, self.age)

Creating a list of people

avi, bill, bob, harry = Person('Avi', 23), Person('Bill', 41), Person('Bob', 77), Person('Harry', 55)

people = List(avi, bill, bob, harry)

Use LINQ selections, write cleaner code

old_people = people.where(lambda p: p.age > 23) # It's a joke! :) [, , ]
old_people.first()                                              # 
old_people.last()                                               # 
old_people.any(lambda p: p.name.lower().startswith('b'))        # True
old_people.where(lambda p: p.age == 55)                         # []
old_people.skip(3).any()                                        # False
old_people.skip(2).first()                                      # 

Isn't it better than "for", "if", "else", "filter", "map" and list comprehensions in the middle of your code?

More selections

new_kids_in_town = [Person('Chris', 18), Person('Danny', 16), Person('John', 17)]
people += new_kids_in_town # Also works: people = people.concat(new_kids_in_town)

teenagers = people.where(lambda p: 20 >= p.age >= 13) danny = teenagers.first(lambda t: t.name == 'Danny') # oldest_teen = teenagers.order_by(lambda t: t.age).last() #

Let's make python more dynamic

names = people.name                                             # ['Avi', 'Bill', 'Bob', 'Harry', 'Chris', 'John']
ages = people.age                                               # [23, 41, 77, 55, 18, 17]
teenagers_names = teenagers.name                                # ['Chris', 'Danny', 'John']
teenagers_names.take(2).except_for(lambda n: n == 'Danny')      # ['Chris']
teenagers.age.min                                               # 16
teenagers.age.avg                                               # 17
teenagers.age.max                                               # 18

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.