https://github.com/etuzon/python-nrt-collections-utils
Collections utilities in Python
https://github.com/etuzon/python-nrt-collections-utils
Last synced: about 2 months ago
JSON representation
Collections utilities in Python
- Host: GitHub
- URL: https://github.com/etuzon/python-nrt-collections-utils
- Owner: etuzon
- License: mit
- Created: 2024-06-16T20:58:06.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-12-16T09:01:01.000Z (5 months ago)
- Last Synced: 2025-03-26T21:52:46.165Z (2 months ago)
- Language: Python
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Collections Utilities
### Collections utilities in Python.





[](https://coveralls.io/github/etuzon/pytohn-nrt-collections-utils)


[](https://app.deepsource.com/gh/etuzon/python-nrt-collections-utils/)## 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**
```python
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**
```python
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. |
| `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**
```python
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.remove_none**Code**
```python
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**
```python
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**
```python
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**
```python
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
```