#!/usr/bin/env python3
import tomlkit
doc = tomlkit.loads("""
x.y.z = 1
[[a]]
x = 1
""")
doc["a"].pop()
doc["x"]["y"].pop("z")
print(f"{doc=}")
rendered = tomlkit.dumps(doc)
print(f"{rendered=}")
result
doc={'x': {'y': {}}, 'a': []}
rendered='\n\n'
Two newlines is not a good TOML representation of that dictionary
result
Two newlines is not a good TOML representation of that dictionary