Skip to main content

Editing deeply nested dicts/lists becomes the easiest thing in the world...

Project description

Library to update nested dicts and lists

You can change the values in a flattened version of your dict that NestedNop creates for you. After you editing, NestedNop updates the original structure automatically.

pip install nestednop 
    dictoriginal=data={'level1': {'t1': {'s1': {'col1': 5, 'col2': 4, 'col3': 4, 'col4': 9},

                   's2': {'col1': 1, 'col2': 5, 'col3': 4, 'col4': 8},

                   's3': {'col1': 11, 'col2': 8, 'col3': 2, 'col4': 9},

                   's4': {'col1': 5, 'col2': 4, 'col3': 4, 'col4': 9}},

            't2': {'s1': {'col1': 5, 'col2': 4, 'col3': 4, 'col4': 9},

                   's2': {'col1': 1, 'col2': 5, 'col3': 4, 'col4': 8},

                   's3': {'col1': 11, 'col2': 8, 'col3': 2, 'col4': 9},

                   's4': {'col1': 5, 'col2': 4, 'col3': 4, 'col4': 9}},

            't3': {'s1': {'col1': 1, 'col2': 2, 'col3': 3, 'col4': 4},

                   's2': {'col1': 5, 'col2': 6, 'col3': 7, 'col4': 8},

                   's3': {'col1': 9, 'col2': 10, 'col3': 11, 'col4': 12},

                   's4': {'col1': 13, 'col2': 14, 'col3': 15, 'col4': 16}}},

    'level2': {'t1': {'s1': {'col1': 5, 'col2': 4, 'col3': 9, 'col4': 9},

                   's2': {'col1': 1, 'col2': 5, 'col3': 4, 'col4': 5},

                   's3': {'col1': 11, 'col2': 8, 'col3': 2, 'col4': 13},

                   's4': {'col1': 5, 'col2': 4, 'col3': 4, 'col4': 20}},

            't2': {'s1': {'col1': 5, 'col2': 4, 'col3': 4, 'col4': 9},

                   's2': {'col1': 1, 'col2': 5, 'col3': 4, 'col4': 8},

                   's3': {'col1': 11, 'col2': 8, 'col3': 2, 'col4': 9},

                   's4': {'col1': 5, 'col2': 4, 'col3': 4, 'col4': 9}},

            't3': {'s1': {'col1': 1, 'col2': 2, 'col3': 3, 'col4': 4},

                   's2': {'col1': 5, 'col2': 6, 'col3': 7, 'col4': 8},

                   's3': {'col1': 9, 'col2': 10, 'col3': 11, 'col4': 12},

                   's4': {'col1': 13, 'col2': 14, 'col3': 15, 'col4': 16}}}}



    from nestednop import NestedNop

    nest=NestedNop(dictoriginal)

    for key, item in nest.iterable_flat.items():

        if item['get_value']() == 4 and key[-1] == 'col3':

            item['set_value'](400000000000000)



    updatediter = nest.get_updated_iterable()





    updatediter

    {'level1': {'t1': {'s1': {'col1': 5,

        'col2': 4,

        'col3': 400000000000000,

        'col4': 9},

       's2': {'col1': 1, 'col2': 5, 'col3': 400000000000000, 'col4': 8},

       's3': {'col1': 11, 'col2': 8, 'col3': 2, 'col4': 9},

       's4': {'col1': 5, 'col2': 4, 'col3': 400000000000000, 'col4': 9}},

      't2': {'s1': {'col1': 5, 'col2': 4, 'col3': 400000000000000, 'col4': 9},

       's2': {'col1': 1, 'col2': 5, 'col3': 400000000000000, 'col4': 8},

       's3': {'col1': 11, 'col2': 8, 'col3': 2, 'col4': 9},

       's4': {'col1': 5, 'col2': 4, 'col3': 400000000000000, 'col4': 9}},

      't3': {'s1': {'col1': 1, 'col2': 2, 'col3': 3, 'col4': 4},

       's2': {'col1': 5, 'col2': 6, 'col3': 7, 'col4': 8},

       's3': {'col1': 9, 'col2': 10, 'col3': 11, 'col4': 12},

       's4': {'col1': 13, 'col2': 14, 'col3': 15, 'col4': 16}}},

     'level2': {'t1': {'s1': {'col1': 5, 'col2': 4, 'col3': 9, 'col4': 9},

       's2': {'col1': 1, 'col2': 5, 'col3': 400000000000000, 'col4': 5},

       's3': {'col1': 11, 'col2': 8, 'col3': 2, 'col4': 13},

       's4': {'col1': 5, 'col2': 4, 'col3': 400000000000000, 'col4': 20}},

      't2': {'s1': {'col1': 5, 'col2': 4, 'col3': 400000000000000, 'col4': 9},

       's2': {'col1': 1, 'col2': 5, 'col3': 400000000000000, 'col4': 8},

       's3': {'col1': 11, 'col2': 8, 'col3': 2, 'col4': 9},

       's4': {'col1': 5, 'col2': 4, 'col3': 400000000000000, 'col4': 9}},

      't3': {'s1': {'col1': 1, 'col2': 2, 'col3': 3, 'col4': 4},

       's2': {'col1': 5, 'col2': 6, 'col3': 7, 'col4': 8},

       's3': {'col1': 9, 'col2': 10, 'col3': 11, 'col4': 12},

       's4': {'col1': 13, 'col2': 14, 'col3': 15, 'col4': 16}}}}

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nestednop-0.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

nestednop-0.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file nestednop-0.1.tar.gz.

File metadata

  • Download URL: nestednop-0.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for nestednop-0.1.tar.gz
Algorithm Hash digest
SHA256 f98b6ec8575898255ed03b80794a03492f100689f3e21051f42d2f16033cea47
MD5 b2d603395ae19fdb90a81917641daf48
BLAKE2b-256 df5c8c3505b8a8d11540e47e90a93631357ef6d6e7c1d1b8be0fcaef46317689

See more details on using hashes here.

File details

Details for the file nestednop-0.1-py3-none-any.whl.

File metadata

  • Download URL: nestednop-0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for nestednop-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 64183e486ee3ac4bf0350d26a0163986a4a73bb8d65b98ebc6f97c3e753c66a2
MD5 e59566f97e168f67d44aafd43582d558
BLAKE2b-256 0699f98ec0bf31a3593d12878f46ed4fe56bf59beb2b92db4a4608ece398b747

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