Skip to main content

A Python package to flatten nested data structures

Project description

Flatten Nested

A Python package for flattening nested data structures including lists, tuples, dictionaries, and sets.

Installation

pip install flatten-nested

Usage

from flatten_nested import flatten

# Flatten a nested list
nested_list = [1, [2, 3, [4, 5]], 6]
flattened = flatten(nested_list)
print(flattened)  # [1, 2, 3, 4, 5, 6]

# Flatten a nested dictionary
nested_dict = {'a': 1, 'b': {'c': 2, 'd': {'e': 3}}}
flattened = flatten(nested_dict)
print(flattened)  # [('a', 1), ('b.c', 2), ('b.d.e', 3)]

# Flatten with depth limit
nested = [1, [2, [3, [4]]]]
flattened = flatten(nested, depth=1)
print(flattened)  # [1, 2, [3, [4]]]

Features

  • Supports lists, tuples, dictionaries, and sets
  • Optional depth limit for partial flattening
  • Customizable dictionary key handling
  • Configurable separator for nested dictionary keys
  • Type hints for better IDE support
  • Comprehensive test suite
  • Exception handling for unsupported types

License

This project is licensed under the MIT License.

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

flatten_nested-0.1.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

flatten_nested-0.1.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file flatten_nested-0.1.1.tar.gz.

File metadata

  • Download URL: flatten_nested-0.1.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.3 Windows/11

File hashes

Hashes for flatten_nested-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e42c8e74a21ad7f8262c5dbfe9fc1792fed978a592e249fdb8c5a45cc2190678
MD5 de938e858304a1b5c7e7bd27f6b0ca8d
BLAKE2b-256 467466158f2ca43d5fa5ac28a8b786bed83e756625330a6e92c47db836e51fa6

See more details on using hashes here.

File details

Details for the file flatten_nested-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: flatten_nested-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.3 Windows/11

File hashes

Hashes for flatten_nested-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 02593d59a1a9521463999cc29ff4834a4a6babaa7bd5437bbce2187696e1cae1
MD5 8e8e19905be578296a5483e9fe28845c
BLAKE2b-256 fcffe1765a02f70fb570c24fc3df982e91351255c98159f6a6b66c4c1ae04213

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