Skip to main content

Flatten nested iterable object (Pure-Python)

Project description

flati

travis-ci.org coveralls.io pyversion latest version license

Flatten nested iterable object (Pure-Python implementation)

Installation

$ pip install flati

Usage

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 copy

CHANGES

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 details)

Uploaded Source

File details

Details for the file flati-0.1.2.tar.gz.

File metadata

  • Download URL: flati-0.1.2.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.4

File hashes

Hashes for flati-0.1.2.tar.gz
Algorithm Hash digest
SHA256 93b58c36864e4fb4706815bc31a20399755deea803e2e482dbb1083f20a04131
MD5 d471f1bc768b5c0c9b9ec2c682d952a4
BLAKE2b-256 6b94734b1e7640b62bdcb80e4e6ea37128efe04ef718a60a637ff8de13d7416a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page