def sorted_with_prefix(prefix, it, drop_exact=True, drop_special=True):
    """
    >>> sorted_with_prefix("foo", ["fooZ", "fooAA", "fox"])
    ['fooAA', 'fooZ']
    >>> sorted_with_prefix("", ["fooZ", "fooAA", "_f", "__f", "fox"])
    ['fooAA', 'fooZ', 'fox', '_f']
    >>> sorted_with_prefix("", ["fooZ", "fooAA", "_f", "__f", "fox"], drop_special=False)
    ['fooAA', 'fooZ', 'fox', '_f', '__f']
    """
    key = lambda name: (name.startswith("__"), name.startswith("_"), name)
    return sorted([
        el for el in it
        if el.startswith(prefix) and (not drop_exact or el != prefix)
           and (not drop_special or not el.startswith("__"))
    ], key=key)