Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!/usr/bin/env python3 

2 

3"""Solution to chapter 6, exercise 25: myxml""" 

4 

5 

6def myxml(tagname, content='', **kwargs): 

7 """Takes a tag name (string), an optional content string, 

8and optional kwargs. 

9 

10Returns a string in which "tagname" is an XML tag at the start and end, 

11"content" is placed in the middle of the tags, and 

12the key-value pairs of kwargs are inserted as attributes in the opening tag. 

13""" 

14 attrs = ''.join([f' {key}="{value}"' 

15 for key, value in kwargs.items()]) 

16 return f'<{tagname}{attrs}>{content}</{tagname}>'