<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def tag(tagname, content='', attrs=None):
 """ Helper for programmatically building HTML tags. Note that this barely does any escaping, and will happily spit out dangerous user input if used as such. :param tagname: Tag name of the DOM element we want to return. :param content: Optional content of the DOM element. If `None`, then the element is self-closed. By default, the content is an empty string. Supports iterables like generators. :param attrs: Optional dictionary-like collection of attributes for the DOM element. Example:: u'<div>Hello, world.</div>' u'<script src="/static/js/core.js"></script>' u'<script src="/static/js/core.js" type="text/javascript"></script>' u'<meta content="\\\\"quotedquotes\\\\"" />' u'<ul><li>0</li><li>1</li><li>2</li></ul>' """

    attrs_str = attrs and ' '.join(_generate_dom_attrs(attrs))
    open_tag = tagname
    if attrs_str:
        open_tag += ' ' + attrs_str

    if content is None:
        return literal('<%s />' % open_tag)

    content = ''.join(iterate(content, unless=(basestring, literal)))
    return literal('<%s>%s</%s>' % (open_tag, content, tagname))