def find_index ( segmentation , stroke_id ) : for i , symbol in enumerate ( segmentation ) : for sid in symbol : if sid == stroke_id : return i return - 1
python retrive list index based on its content
>>> find_index ( [[ 0 1 2 ] [ 3 4 ] [ 5 6 7 ]] 0 ) 0 >>> find_index ( [[ 0 1 2 ] [ 3 4 ] [ 5 6 7 ]] 1 ) 0 >>> find_index ( [[ 0 1 2 ] [ 3 4 ] [ 5 6 7 ]] 5 ) 2 >>> find_index ( [[ 0 1 2 ] [ 3 4 ] [ 5 6 7 ]] 6 ) 2
def find_index(segmentation, stroke_id):
    """
    >>> find_index([[0, 1, 2], [3, 4], [5, 6, 7]], 0)
    0
    >>> find_index([[0, 1, 2], [3, 4], [5, 6, 7]], 1)
    0
    >>> find_index([[0, 1, 2], [3, 4], [5, 6, 7]], 5)
    2
    >>> find_index([[0, 1, 2], [3, 4], [5, 6, 7]], 6)
    2
    """
    for i, symbol in enumerate(segmentation):
        for sid in symbol:
            if sid == stroke_id:
                return i
    return -1