Skip to main content

Collections utilities in Python

Project description

Collections Utilities

Collections utilities in Python.

PyPI PyPI - Python Version PyPI - License PyPI - Downloads PyPI - Downloads Coverage Status GitHub code size in bytes GitHub last commit DeepSource

CollectionsUtil class

Methods

Method Description Parameters Returns
deep_args_to_list Flat deep structure arguments to list. args (tuple) The arguments to flat. list A flatten list.
is_iter Check if object is iterable. obj The object to check. bool True if iterable, False otherwise.
object_to_deep_collection Convert object to deep collection. obj The object to convert. dict, list, set, tuple A deep collection.

Examples:

  • CollectionsUtil.deep_args_to_list

    Code

    from nrt_collections_utils.collections_utils import CollectionsUtil
    
    # Flat deep structure arguments to list
    flat_args = CollectionsUtil.deep_args_to_list(1, 2, (3, 4, (5, 6, (7, 8, 9))))
    print(flat_args)
    

    Output

    [1, 2, 3, 4, 5, 6, 7, 8, 9]
    
  • CollectionsUtil.is_iter

    Code

    from nrt_collections_utils.collections_utils import CollectionsUtil
    
    # Check if object is iterable
    print(CollectionsUtil.is_iter(1))
    print(CollectionsUtil.is_iter([1, 2, 3]))
    

    Output

    False
    True
    

ListUtil class

Methods

Method Description Parameters Returns
compare_lists Compare two lists. list_1 (list) List 1.
list_2 (list) List 2.
bool True if lists are equal, False otherwise.
get_intersection_list Get intersection of two lists. list_1 (list) List 1.
list_2 (list) List 2.
list The intersection of the two lists.
remove_none Remove None values. list_ (list) The list to remove None values from. list The list without None values.
remove_duplicates Remove duplicates. list_ (list) The list to remove duplicates from. list The list without duplicates.
remove_empty Remove empty values. list_ (list) The list to remove empty values from. list The list without empty values.

Examples:

  • ListUtil.compare_lists

    Code

    from nrt_collections_utils.list_utils import ListUtil
    
    # Compare two lists
    print(ListUtil.compare_lists([1, 3, 2], [1, 2, 3]))
    print(ListUtil.compare_lists([1, 2, 3], [1, 2, 4]))
    

    Output

    True
    False
    
  • ListUtil.get_intersection_list

    Code

    from nrt_collections_utils.list_utils import ListUtil
    
    # Get intersection of two lists
    print(ListUtil.get_intersection_list([1, 2, 3], [2, 3, 4]))
    

    Output

    [2, 3]
    
  • ListUtil.remove_none

    Code

    from nrt_collections_utils.list_utils import ListUtil
    
    # Remove None values
    print(ListUtil.remove_none([1, None, 2, None, 3]))
    

    Output

    [1, 2, 3]
    
  • ListUtil.remove_duplicates

    Code

    from nrt_collections_utils.list_utils import ListUtil
    
    # Remove duplicates
    print(ListUtil.remove_duplicates([1, 2, 3, 1, 2, 3]))
    

    Output

    [1, 2, 3]
    
  • ListUtil.remove_empty

    Code

    from nrt_collections_utils.list_utils import ListUtil
    
    # Remove empty values
    print(ListUtil.remove_empty([1, '', 2, None, 3, '']))
    

    Output

    [1, 2, 3]
    

DictUtil class

Methods

Method Description Parameters Returns
get_value Get value from dict. dict_ (dict) The dict to get value from.
path [str, list] The path to the value.
default_value Default value in case the value is None
Any The value.

Examples:

  • DictUtil.get_value

    Code

    from nrt_collections_utils.dict_utils import DictUtil
    
    # Get value from dict
    print(DictUtil.get_value({'a': {'b': {'c': 1}}}, ['a', 'b', 'c']))
    

    Output

    1
    

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

nrt_collections_utils-1.0.4.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

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

nrt_collections_utils-1.0.4-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file nrt_collections_utils-1.0.4.tar.gz.

File metadata

  • Download URL: nrt_collections_utils-1.0.4.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for nrt_collections_utils-1.0.4.tar.gz
Algorithm Hash digest
SHA256 c723f7a056368b1b013784f53cf9180f8875331dd61b1c7aba22dec47dec1fc9
MD5 0017f5cd5abafb0b0a29edf98875d3a3
BLAKE2b-256 727372c6fee5d350fe63cfebadbdb051d803641f71e45e616e2685aaa99a81f6

See more details on using hashes here.

File details

Details for the file nrt_collections_utils-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for nrt_collections_utils-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5c7233742da41ab52e72b528166c35c93ddf6e33cc2f28d8be339dba2c95541a
MD5 d9c9857f5115646821faee7ee65a821d
BLAKE2b-256 d9c2fc1b8bf1fdfa92cd15d18d790819ac8d916ee1bf1cecf5dd66d8299fcfba

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