def sort(items, key=None, start_with_none=False, reverse=False):
    """
    Sorts a list (or any other iterable). It differs from built-in
    function ``sorted`` by treating ``None`` keys in a special way:
    they are all gathered either in the end of the result (default),
    or in the beginning. It also constructs the list and returns it
    completely instead of yielding.

    Args:
        items: any finite iterable

        key: optional, function ``item -> bool``

        start_with_none: if ``True``, items with ``None`` keys will
            go first.

        reverse: sort in the decrementing order

    Returns: a sorted list
    """
    if key is not None:
        not_nones = [item for item in items if key(item) is not None]
        nones = [item for item in items if key(item) is None]
    else:
        not_nones = [item for item in items if item is not None]
        nones = [item for item in items if item is None]
    not_nones = sorted(not_nones, key=key, reverse=reverse)
    return nones + not_nones if start_with_none else not_nones + nones