maci.cleanformat

formats data to a cleaner structured output

Formats and dumps dictionaries, lists, tuples, and sets to a string formatted in a clean human-readable structure. Useful for nested data to be represented over multiple lines with indentation.

maci.cleanformat -> str

Basic Example of formatting data to a string using default positional parameter

data = maci.cleanformat(nested_data)

In this example, we simply format nested data to a string using the cleanformat function and pass the data as an argument to the function, and assign the returned string data to a variable.

Example output using cleanformat with nested dictionary data

{
    'k1': 'value1',
    'k2': {
        'sub1': 'sub_value1',
        'sub2': {
            'sub_sub1': 'sub_sub_value1',
        },
        'sub3': 'sub_value3',
    },
    'k3': 'value3',
}

Example output using cleanformat with nested list data

[
    1,
    [
        1,
        2,
        [
            1,
            2,
            3,
        ],
        3,
    ],
    2,
    3,
]

parameters & arguments

Describes all parameter functionality and accepted data types

data: dict | list | tuple | set

First and only required positional argument. Accepts dictionaries, lists, tuples, and sets

Use this parameter to pass in the data you want to format

indent_level: int

Optional parameter. Accepts integers. Default = 1

Use this parameter to change the indentation level for structured data (lists, dicts, tuples, sets) in the output. Indentation will be applied to nested data.

Default uses the standard 4x spaces indentation practice. A single integer represents adding 4x more spaces at each level. For example 1 = 4x spaces, 2 = 8x spaces, 3 = 12x spaces, etc.

Note: Setting it to 0 will slightly improve write performance by approx 5%.

Last updated