Skip to main content

Utils for filtering

Project description

kc

Utils for filtering

To install: pip install kc

Overview

The kc package provides utility functions for creating filters that can be applied to data collections in Python. These filters allow for inclusion or exclusion of elements based on specified criteria. The package is particularly useful for filtering lists, tuples, or other iterable collections based on dynamic conditions.

Main Functions

mk_inclusion_exclusion_filter

This function creates a filter based on both inclusion and exclusion criteria. It returns a filter function that can be used with Python's built-in filter() function.

  • Parameters:

    • include: List-like collection of elements to include.
    • exclude: List-like collection of elements to exclude.
    • key: A function or a key to apply to elements of the iterable for comparison.
  • Usage Example:

    # Inclusion only
    filt = mk_inclusion_exclusion_filter(include=[2, 4])
    print(list(filter(filt, [1, 2, 3, 4, 5])))
    
    # Exclusion only
    filt = mk_inclusion_exclusion_filter(exclude=[2, 4])
    print(list(filter(filt, [1, 2, 3, 4, 5])))
    
    # Inclusion and Exclusion
    filt = mk_inclusion_exclusion_filter(include=[1, 2, 3, 4], exclude=[1, 3])
    print(list(filter(filt, [1, 2, 3, 4, 5])))
    

mk_inclusion_filter

Creates a filter that includes elements if they are in the specified include list.

  • Parameters:

    • include: List-like collection of elements to include.
    • key: A function or a key to apply to elements of the iterable for comparison.
  • Usage Example:

    filt = mk_inclusion_filter(include=[2, 4])
    print(list(filter(filt, [1, 2, 3, 4, 5])))
    

mk_exclusion_filter

Creates a filter that excludes elements if they are in the specified exclude list.

  • Parameters:

    • exclude: List-like collection of elements to exclude.
    • key: A function or a key to apply to elements of the iterable for comparison.
  • Usage Example:

    filt = mk_exclusion_filter(exclude=[2, 4])
    print(list(filter(filt, [1, 2, 3, 4, 5])))
    

Installation

To install the kc package, use the following command:

pip install kc

Contributing

Contributions to the kc package are welcome. Please ensure that any pull requests or issues are clear and provide sufficient information for review.

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

kc-0.0.6.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kc-0.0.6-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file kc-0.0.6.tar.gz.

File metadata

  • Download URL: kc-0.0.6.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.13

File hashes

Hashes for kc-0.0.6.tar.gz
Algorithm Hash digest
SHA256 85138606d4dfe8e4eba566fcd2b9d177c1b1ef90b53a4314411556c35320eae9
MD5 0abba7dcbe7ce7ea24486e9b999f1739
BLAKE2b-256 cde106b6b246b06853bafa95f31fe0cc4bfdc3ff310a0ebf7140f4c47171bb8d

See more details on using hashes here.

File details

Details for the file kc-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: kc-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.13

File hashes

Hashes for kc-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ef67679806d02e0dccdb334b316494e30a62167f6c643a8d806534d0e25cda55
MD5 a52d4a2511c7b8e408e5a82a9c5d5148
BLAKE2b-256 4ef2ffa7782800d62beccb9554224635f443a6964f6f0cda93ab6a7c04a99528

See more details on using hashes here.

Supported by

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