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.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: flatten_nested-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 489375c1399d2039f34d773d87b1f10c642c9956d7e1548d514c723f6004a41e
MD5 758787836da3dacf38d2126bbc684f4f
BLAKE2b-256 bd25dc57cf6df067dc657eb07ac16971f13e376527c4a6e676f073e89c8b3797

See more details on using hashes here.

File details

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

File metadata

  • Download URL: flatten_nested-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 df10358c024c2c3bbab1187a3131073efb49cc648a7ab82c76a2f04c59c24a99
MD5 589a2014eba22b9fbe374bfc55eb4d3b
BLAKE2b-256 f002f0512534ff2fc955776baeefb5a236ef64f65bfd2abcafebd922024b9963

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