有两个细微差别:(1)如果列表中没有元素需要删除之前的其余元素,则列表不应更改。(2) 如果列表为空,则它必须保持为空。
def remove_all_before(items: list, border: int) -> Iterable:
if border in items:
for i in range(len(items)):
if items != border:
items.remove(items[i])
a = i
items.remove(items[a])
return items
else:
return items
else:
return items
print((remove_all_before([1, 2, 3, 4, 5], 3))) #[3, 4, 5]
print((remove_all_before([1, 1, 2, 2, 3, 3], 2))) #[2, 2, 3, 3]
print((remove_all_before([1, 1, 2, 4, 2, 3, 4], 2))) #[2, 4, 2, 3, 4]
print((remove_all_before([1, 1, 5, 6, 7], 2))) #[1, 1, 5, 6, 7]
print((remove_all_before([], 0))) #[]
print((remove_all_before([7, 7, 7, 7, 7, 7, 7, 7, 7], 7))) #[7, 7, 7, 7, 7, 7, 7, 7, 7]
我不知道如何通过七人制的最后一次检查,不再可能制作三明治并帮助我在 lambda 表达式中呈现这段代码(在打印右侧的注释中应该是最终结果)
规则 1:永远不要更改原始列表,您需要创建一个新列表。
在这种情况下,创建一个新列表根本没有意义,因为您可以简单地返回原始列表的一部分: