444
社区成员
发帖
与我相关
我的任务
分享代码:
array = [10, 5, 2, 3, 11]
pivot = array[0]
less = [i for i in array[1:] if i <= pivot]
print(less)
等价于:
array = [10, 5, 2, 3, 11]
pivot = array[0]
less = []
for i in array[1:]:
if i <= pivot:
less.append(i)
print(less)
结果为:
[5, 2, 3]