我现在正在学习Python,并接触了快速排序算法。下面是我已经编写的带有示例列表的代码:
[3,1,2,2,1,3,6,7,5,4,8]
def quick(self):
first = self.lst[0]
l1 = []
l2 = []
for item in self.lst[1:]:
if item <= first:
l1.append(item)
print('this is l1:',l1)
else:
l2.append(item)
print('this is l2:', l2)
return _____
我正在尝试执行self.lst = l1 + first + l2
,但是当我这样做时,我收到一个错误,指出:
self.lst = l1 + first + l2
builtins.TypeError: can only concatenate list (not "int") to list
我正在尝试正确地进行第一次操作,也许会实现一个while True until l1 = []
或类似的东西。
- 如何将l1、first和l2连接在一起?
- 在完成第一步之后,你们建议我做什么?
非常感谢!