https://github.com/ikegami-yukino/flati
Flatten nested iterable object for Python (Pure-Python implementation)
https://github.com/ikegami-yukino/flati
flatten pure-python
Last synced: 3 months ago
JSON representation
Flatten nested iterable object for Python (Pure-Python implementation)
- Host: GitHub
- URL: https://github.com/ikegami-yukino/flati
- Owner: ikegami-yukino
- License: mit
- Created: 2019-01-27T06:34:55.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-01T13:38:24.000Z (over 5 years ago)
- Last Synced: 2024-10-13T09:49:51.507Z (9 months ago)
- Topics: flatten, pure-python
- Language: Python
- Homepage:
- Size: 17.6 KB
- Stars: 28
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
flati
==========
|travis| |coveralls| |pyversion| |version| |license|Flatten nested iterable object (Pure-Python implementation)
Japanese document is available: https://qiita.com/yukinoi/items/9570c76034c28bdae0a8
Installation
==============::
$ pip install flati
Usage
============.. code:: python
import flati
iterable = [(1, 2, 3), (4, (5, 6))]
list(flati.flatten(iterable))
# => [1, 2, 3, 4, 5, 6]# flati.flatten() 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']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 copyContribution
=============
Contributions are welcome.See https://github.com/ikegami-yukino/flati/blob/master/CONTRIBUTING.md
.. |travis| image:: https://travis-ci.org/ikegami-yukino/flati.svg?branch=master
:target: https://travis-ci.org/ikegami-yukino/flati
:alt: travis-ci.org.. |coveralls| image:: https://coveralls.io/repos/ikegami-yukino/flati/badge.svg?branch=master&service=github
:target: https://coveralls.io/github/ikegami-yukino/flati?branch=master
:alt: coveralls.io.. |pyversion| image:: https://img.shields.io/pypi/pyversions/flati.svg
.. |version| image:: https://img.shields.io/pypi/v/flati.svg
:target: http://pypi.python.org/pypi/flati/
:alt: latest version.. |license| image:: https://img.shields.io/pypi/l/flati.svg
:target: http://pypi.python.org/pypi/flati/
:alt: license