Skip to content

The linq module in C# has been adapted for python with some modifications. Provides simple to use LINQ features to Python 3.x.

License

Notifications You must be signed in to change notification settings

TahsinCr/python-linqex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn

Logo Logo


Logo

Python Linqex

The linq module in C# has been adapted for python with some modifications.

Changelog · Report Bug · Request Feature

Table of Contents
  1. About The Project

  2. Getting Started

  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

About The Project

Provides simple to use LINQ features to Python 3.x.

(back to top)

Built With

  • python-shield

(back to top)

Getting Started

To get a local copy up and running follow these simple example steps.

Prerequisites

Does not require any prerequisites

Installation

  1. Clone the repo
git clone https://github.com/TahsinCr/python-linqex.git
  1. Install PIP packages
pip install linqex

(back to top)

Usage

Let's have different customers. Let's choose the male ones among these customers. For this:

from linqex.linq import Enumerable
customersList = [
    {'name' : 'Jonh', 'age' : 25, 'gender': 'male'},
    {'name' : 'Emma', 'age' : 44, 'gender': 'female'},
    {'name' : 'Steve', 'age' : 17, 'gender': 'male'}
]

customersEnumerable = Enumerable(customersList)

# to select only male ones:
customersMaleEnumerable = customersEnumerable.Where(lambda key, value: value['gender'] == 'male')

for customer in customersMaleEnumerable.ToList:
    print(customer)

Output

{'name' : 'Jonh', 'age' : 25, 'gender': 'male'}
{'name' : 'Steve', 'age' : 17, 'gender': 'male'}

Let's develop the example we wrote above a bit further:

from typing import Literal
from linqex.linq import Enumerable

MALE = "MALE"
FEMALE = "FEMALE"

class Customer:
    def __init__(self, id:int, name:str, age:int, gender:Literal["MALE","FEMALE"]):
        self.id = id
        self.name = name
        self.age = age
        self.gender = gender


customerList = [
    Customer(1, "Ava", 32, MALE),
    Customer(2, "Alex", 19, MALE),
    Customer(3, "Amelia", 22, FEMALE),
    Customer(4, "Arnold", 43, MALE),
    Customer(5, "Eric", 55, MALE),
    Customer(6, "Lily", 12, FEMALE),
    Customer(7, "Jessia", 32, MALE),
    Customer(8, "William", 19, MALE),
    Customer(9, "Emily", 22, FEMALE),
    Customer(10, "Mateo", 43, MALE),
    Customer(11, "Antony", 55, MALE),
    Customer(12, "Mia", 12, FEMALE)
]

customerEnumerable = Enumerable.List(customerList)

# to select only male ones:
customersMaleEnumerable = customerEnumerable.Where(lambda customer: customer.gender == MALE)

customersMaleEnumerable.Loop(lambda customer: print(customer.__dict__))

Output

{'id': 1, 'name': 'Ava', 'age': 32, 'gender': 'MALE'}
{'id': 2, 'name': 'Alex', 'age': 19, 'gender': 'MALE'}
{'id': 4, 'name': 'Arnold', 'age': 43, 'gender': 'MALE'}
{'id': 5, 'name': 'Eric', 'age': 55, 'gender': 'MALE'}
{'id': 7, 'name': 'Jessia', 'age': 32, 'gender': 'MALE'}
{'id': 8, 'name': 'William', 'age': 19, 'gender': 'MALE'}
{'id': 10, 'name': 'Mateo', 'age': 43, 'gender': 'MALE'}
{'id': 11, 'name': 'Antony', 'age': 55, 'gender': 'MALE'}

For more examples, please refer to the Documentation

(back to top)

Roadmap

  • Add Changelog

  • Improve The Testing Infrastructure

  • Add Documents

  • Add Additional Templates w/ Examples

  • Add Decorators

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".

Don't forget to give the project a star! Thanks again!

  1. Fork the Project

  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)

  3. Commit your Changes (git commit -m 'Add some AmazingFeature')

  4. Push to the Branch (git push origin feature/AmazingFeature)

  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Email: TahsinCr@outlook.com

X: @TahsinCrs

LinkedIn: TahsinCr

(back to top)

Acknowledgments

(back to top)

About

The linq module in C# has been adapted for python with some modifications. Provides simple to use LINQ features to Python 3.x.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages