avilum / linqit Goto Github PK
View Code? Open in Web Editor NEWExtend python lists operations using .NET's LINQ syntax for clean and fast coding.
License: Apache License 2.0
Extend python lists operations using .NET's LINQ syntax for clean and fast coding.
License: Apache License 2.0
sucks teeth
Harsh.
In looking at the code I can see that the all/any methods traverse the whole list. I have a tested fix with short circuiting for these methods...but have never done pull requests...
Hey, great library. I would love to do something like this but seems to just use the substandard built-in list implementation which returns None:
people = List()
people.append(Person("Michael", 47))
people.append(Person("Sarah", 50))
people.append(Person("Jake", 42))
older = people.where(lambda p: p.age > 43).sort(lambda p: -p.age)
But sadly, sort returns None and I didn't see an order_by
, what am I missing?
The README says:
from linqit import List
programmers = List()
Avi = type('Avi', (), {})
# Go ahead and fill the list with whatever you want... like a list of <Programmer> objects.
# Then play:
last_hot_pizza_slice = programmers.where(lambda e:e.experience > 15)
.except_for(elon_musk)
.of_type(Avi)
.take(3) # [<Avi>, <Avi>, <Avi>]
.select(lambda avi:avi.lunch) # [<Pizza>, <Pizza>, <Pizza>]
.where(lambda p:p.is_hot() and p.origin != 'Pizza Hut').
.last() # <Pizza>
.slices.last() # <PizzaSlice>
# What do you think?
I think there's a syntax error… .except_for(elon_musk)
is not part of the last_hot_pizza_slice = …
statement. You may add parenthesis around the whole statement.
I also think that there is an extra dot after p.origin != 'Pizza Hut')
You may also use black to format the code. This would finally give:
from seven_dwwarfs import Grumpy, Happy, Sleepy, Bashful, Sneezy, Dopey, Doc
from linqit import List
programmers = List()
Avi = type("Avi", (), {})
# Go ahead and fill the list with whatever you want... like a list of <Programmer> objects.
# Then play:
last_hot_pizza_slice = (
programmers.where(lambda e: e.experience > 15)
.except_for(elon_musk)
.of_type(Avi)
.take(3) # [<Avi>, <Avi>, <Avi>]
.select(lambda avi: avi.lunch) # [<Pizza>, <Pizza>, <Pizza>]
.where(lambda p: p.is_hot() and p.origin != "Pizza Hut")
.last() # <Pizza>
.slices.last() # <PizzaSlice>
)
# What do you think?
BTW, your project seems fun to try, thanks for what you've done.
Jokes apart, I absolutely love this, hope this moves to something that can be pip installable!
Cheers 🍻
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') # <Person name="Danny" age="16">
oldest_teen = teenagers.last() # <Person name="Chris" age="18">
.last() method doesn't return max age but the last in the list, right? Should return "John,17 yo" then.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.