Flatten nested iterable object (Pure-Python)
Project description
flati
Flatten nested iterable object (Pure-Python implementation)
Japanese document is available: https://qiita.com/yukinoi/items/9570c76034c28bdae0a8
Installation
$ pip install flati
Usage
import flati
iterable = [(1, 2, 3), (4, (5, 6))]
list(flati.flatten(iterable))
# => [1, 2, 3, 4, 5, 6]
# The flati.flatten function returns a generator
import types
isinstance(flati.flatten(iterable), types.GeneratorType)
# => True
# If you want to avoid flattening specific type, then use "ignore" parameter
iterable = [('abc'), ('def', ('g', 'hi'))]
list(flati.flatten(iterable, ignore=str))
# => ['abc', 'def', 'g', 'hi']
# The flatten_non_str function is alias of "flatten(iterable, ignore=str)"
iterable = [('abc'), ('def', ('g', 'hi'))]
list(flati.flatten_non_str(iterable))
# => ['abc', 'def', 'g', 'hi']
Tips
If you want to flatten numpy.ndarray, I recommend using following methods:
numpy.ravel()
ndarray.reshape(-1)
ndarray.flatten() # This method is a bit slow because it makes a copy
Contribution
Contributions are welcome.
See https://github.com/ikegami-yukino/flati/blob/master/CONTRIBUTING.md
CHANGES
0.2.1 (2025-08-15)
Add flatten_non_str function that alias of flatten(iterable, ignore=str)
0.2.0 (2025-08-02)
Add stub files according to PEP 561
Support Python 3.9, 3.10, 3.11, 3.12, 3.13
0.1.2 (2019-12-31)
Support Python 3.8
0.1.1 (2019-1-28)
Support Python 2.7
0.1 (2019-1-27)
First release
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flati-0.2.1.tar.gz.
File metadata
- Download URL: flati-0.2.1.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e23b2b3664eefdc80cc59bf45927a86765eec5ef54e61a05335afde47523911
|
|
| MD5 |
fab201c2ba835b365458b19d7d99ce33
|
|
| BLAKE2b-256 |
522c2a9aad4f627f668b094f32e0f2741b38bf7c9313012f2e7233da15fd6dbb
|
File details
Details for the file flati-0.2.1-py3-none-any.whl.
File metadata
- Download URL: flati-0.2.1-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.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
507ff989d38b3cf80cdffb424c0f0afdf8a27874170cc0d27bf58c60bcdb0258
|
|
| MD5 |
dfad9e0c300d7d8b4dc6811b0faf6287
|
|
| BLAKE2b-256 |
8a2d0a2ce180ab3c745e297bb296753fb65a4662ab69d421d108f70f8cc91cfd
|