<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _set_extent(ax, projection, extent, extrema):
 """ Sets the plot extent. Parameters ax : cartopy.GeoAxesSubplot instance The axis whose boundaries are being tweaked. projection : None or geoplot.crs instance The projection, if one is being used. extent : None or (xmin, xmax, ymin, ymax) tuple A copy of the ``extent`` top-level parameter, if the user choses to specify their own extent. These values will be used if ``extent`` is non-``None``. extrema : None or (xmin, xmax, ymin, ymax) tuple Plot-calculated extrema. These values, which are calculated in the plot above and passed to this function (different plots require different calculations), will be used if a user-provided ``extent`` is not provided. Returns ------- None """

    if extent:
        xmin, xmax, ymin, ymax = extent
        xmin, xmax, ymin, ymax = max(xmin, -180), min(xmax, 180), max(ymin, -90), min(ymax, 90)

        if projection:  # Input ``extent`` into set_extent().
            ax.set_extent((xmin, xmax, ymin, ymax), crs=ccrs.PlateCarree())
        else:  # Input ``extent`` into set_ylim, set_xlim.
            ax.set_xlim((xmin, xmax))
            ax.set_ylim((ymin, ymax))

    else:
        xmin, xmax, ymin, ymax = extrema
        xmin, xmax, ymin, ymax = max(xmin, -180), min(xmax, 180), max(ymin, -90), min(ymax, 90)

        if projection:  # Input ``extrema`` into set_extent.
            ax.set_extent((xmin, xmax, ymin, ymax), crs=ccrs.PlateCarree())
        else:  # Input ``extrema`` into set_ylim, set_xlim.
            ax.set_xlim((xmin, xmax))
            ax.set_ylim((ymin, ymax))