Skip to main content

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

Project description

Contributors Forks Stargazers Issues MIT License LinkedIn

Python Linqex

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

Changelog · Report Bug · Request Feature

About The Project

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

Built With

  • Python

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

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

License

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


Contact

Tahsin Çirkin - @TahsinCrs - TahsinCr@outlook.com

Project Link: https://github.com/TahsinCr/python-linqex

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

linqex-1.6.3.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

linqex-1.6.3-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file linqex-1.6.3.tar.gz.

File metadata

  • Download URL: linqex-1.6.3.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for linqex-1.6.3.tar.gz
Algorithm Hash digest
SHA256 3dcab21b3963a3caef16efdf766b13167b78d6ed7eeb970ced1e27ae3350bdac
MD5 0ebb15636b25ab94e8a9862d8b51b93e
BLAKE2b-256 730da974f706dae6e7abd5d9b59d80115e83b59b452249add6ac14e50dcbb459

See more details on using hashes here.

File details

Details for the file linqex-1.6.3-py3-none-any.whl.

File metadata

  • Download URL: linqex-1.6.3-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for linqex-1.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e8959328a7cca758bca9c442dc09dfc6828a5c669dd33353e814547a4c2a38c8
MD5 0cc061fe3a56cda2a4f63081a6b4ac8e
BLAKE2b-256 b23aceb8a4bba06627bff723de23e1b5093dd172754513b1d16eee4e1dec3f58

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page