Skip to main content

Flatten nested iterable object (Pure-Python)

Project description

flati pyversion latest version license

Flatten nested iterable object (Pure-Python implementation)


$ pip install flati


import flati

iterable = [(1, 2, 3), (4, (5, 6))]
# => [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']


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


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

flati-0.1.2.tar.gz (3.5 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page