def contained_items_once(str, start, end):
    """
    Given a string that represents items as asterisks (*) and compartment walls 
    as pipes (|), a start index, and an end index, return the number of items in a closed compartment.

    >>> str = '|**|*|*'
    >>> contained_items_once(str, 0, 5)
    2
    >>> contained_items_once(str, 0, 6)
    3
    >>> contained_items_once(str, 1, 7)
    1
    """
    substr = str[start:end].strip('*')
    splits = substr.split('|')
    return sum(len(s) for s in splits)