def stop_at ( iterable , idx ) : for i , item in enumerate ( iterable ) : if i == idx : return yield item
python iterat with index and element
Stops iterating before yielding the specified idx .
def stop_at(iterable, idx):
    """Stops iterating before yielding the specified idx."""
    for i, item in enumerate(iterable):
        if i == idx: return
        yield item