When a dictionary’s keys and values must be processed together, items() supplies one key-value pair per iteration. Unpack each pair into names such as key and value, then transform or format them. section 7.27
Building attributes from keyword arguments
def myxml(tagname, content='', **kwargs): attrs = ''.join([f' {key}="{value}"' for key, value in kwargs.items()]) return f'<{tagname}{attrs}>{content}</{tagname}>' Here, kwargs.items() feeds each attribute name and value to the list comprehension, whose strings are then joined into the opening tag. section 6.2
Transforming dictionary values
A dictionary comprehension can iterate through items(), preserve each key, apply func(value), and use the result as the corresponding new value. section 7.27
def myxml(tagname, content='', **kwargs):
attrs = ''.join([f' {key}="{value}"'
for key, value in kwargs.items()])
return f'<{tagname}{attrs}>{content}</{tagname}>'
Compare the complete function with simpler versions that add a tag and content before processing keyword-argument attributes. section 6.2

