def html_starttag_and_attrs(tag, attrs, startendtag=False):
    """Utility functon to reconstruct starttag and attrs

    Params:

    - tag (str): HTML element tag
    - attrs (list): HTML element attributes formatted as a list of tuples
    - startendtag (bool, False): Flag to handle startend tags

    Example:

    ```
    html_starttag_and_attrs('a', [('href', 'localhost:8000')])
    # ('<a href="localhost:8000">', {'href': 'localhost:8000'})
    ```
    """
    if attrs:
        attrs = dict(attrs)
        af = [f'{k}="{v}"' for k, v in attrs.items()]
        af = f' {" ".join(af)}'
    else:
        attrs = {}
        af = ""
    if startendtag:
        html = f"<{tag}{af} />"
    else:
        html = f"<{tag}{af}>"
    return html, attrs