def popitems(dictionary):
    """Like ``dict.popitem()`` but iterates over all ``(key, value)`` pairs,
    emptying the input ``dictionary``.  Useful for maintaining a lower memory
    footprint at the expense of some additional function calls.

    Parameters
    ----------
    dictionary : dict
        ``dict()`` to process.

    Yields
    ------
    tuple
        ``(key, value)``
    """
    while True:
        try:
            yield dictionary.popitem()
        except KeyError:
            raise StopIteration
