min() arg is an empty sequence

前端 未结 4 1180
逝去的感伤
逝去的感伤 2021-02-20 07:32

I\'m trying to find minimum element in matrix row, but there are two conditions: 1) it must be > 0 2) and this point must be not visited(is_visited[k] is False) I\'

4条回答
  •  故里飘歌
    2021-02-20 07:52

    Try this - it creates the list of x values xs and then only tries to find the min if xs is non-empty. You may need to add some logic to handle the case that xs is empty, depending on what your code is doing.

    for k in range(4):
        if is_visited[k] is False and i != k:
            xs = [x for x in matr_sum[i] if x > 0]
            if xs and matr_sum[i][k] == min(xs):
                return k
    

提交回复
热议问题