Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Recursively convert lists to tuples, sets to frozensets, dicts to mappingproxy etc.

Project description

Recursively convert lists to tuples, sets to frozensets, dicts to mappingproxy etc.

Example usage::

import freezedata

data = {'a': [1,2,3], 'b': {1,2,3}, 'c': {1:1, 2:2, 3:3}}
frozendata = freezedata.freeze_data(data)
print(frozendata)
>> {'a': (1, 2, 3), 'b': frozenset({1, 2, 3}), 'c': mappingproxy({1: 1, 2: 2, 3: 3})}

This is an immutable data structure, that is; there is no direct way to alter this
data structure (without using some special modules(gc, inspect)). For example::

frozendata[c'][4] = 4
>> TypeError: 'mappingproxy' object does not support item assignment
del frozendata['b']
>> TypeError: 'mappingproxy' object does not support item deletion

**Notice**: Since a `mappingproxy` is not hashable, frozen data
structures containing `mappingproxy`s (i.e. based on `dict`s) will not be
hashable either::

hash(frozendata)
>> TypeError: unhashable type: 'mappingproxy'

Project details


Download files

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

Files for freezedata, version 2.2.1
Filename, size File type Python version Upload date Hashes
Filename, size freezedata-2.2.1.tar.gz (3.8 kB) File type Source Python version None Upload date Hashes View

Supported by

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