def isplit(seq, fn):
    """
    Create two lists containing all items in seq,
    depending on the result of calling fn on each item.
    Returns a tuple of (seq where true, seq where false)

    Turns out there's not really a nice, elegant way to do this when iterating
    over the list only once. See https://stackoverflow.com/q/949098

    But, hmm, this might be better:
    from itertools import tee
    def split_on_condition(seq, condition):
        l1, l2 = tee((condition(item), item) for item in seq)
        return (i for p, i in l1 if p), (i for p, i in l2 if not p)
    """
    true = []
    false = []
    for item in seq:
        if fn(item):
            true.append(item)
        else:
            false.append(item)
    return true, false
