def _format_addresses(addresses):
    """Return a formatted string of networks and IP addresses

    :param addresses: a dict of network IP addresses
    :rtype: a string of semi-colon separated networks and IP addresses
    """

    if not addresses:
        return ""

    output = []
    for (network, addr_list) in addresses.items():
        if not addr_list:
            continue
        addresses_csv = ', '.join(
            [addr['addr'] for addr in addr_list]
        )
        group = "%s=%s" % (network, addresses_csv)
        output.append(group)
    return '; '.join(sorted(output))