我认为您必须找到第一个正值并使用它的位置rows
编辑:我将名称count改为last,使之更具可读性# - function -
def move(data):
rows = len(data)
# - find positive -
for x in range(rows):
if data[x][-1] > 0:
rows = x # use its position as `rows`
break # don't seach other positiove values
# - star moving -
# set "last" checked row
last = rows-1
# check "last" row
if data[last][-1] == 0:
# move previous values
while last > 0:
data[last][-1] = data[last-1][-1]
last -= 1
# put 0 in first place
data[0][-1] = 0
# - tests -
examples = [
{
# Condition 1 - Works
'data': [[0, 0, -1], [0, 0, -2], [0, 0, -3], [0, 0, 0], [0, 0, 0]],
'expected': [[0, 0, 0], [0, 0, -1], [0, 0, -2], [0,