Python,递归附加列表

rows = []

def rec(diry,level):
    if level == 2:
        diry['column_{}'.format(level)] = level
        rows.append(diry)
    else:
        diry['column_{}'.format(level)] = level
        rows.append(diry)
        rec(diry,level+1)

rec({},0)
print(rows)

上面的代码打印

[{'column_0': 0, 'column_1': 1, 'column_2': 2},
 {'column_0': 0, 'column_1': 1, 'column_2': 2},
 {'column_0': 0, 'column_1': 1, 'column_2': 2}]

它不应该打印吗

[{'column_0': 0},
 {'column_0': 0, 'column_1': 1},
 {'column_0': 0, 'column_1': 1, 'column_2': 2}]

任何建议都会有所帮助。谢谢

评论