我正在运行从git获得的bubble_sort脚本https://github.com/engineer-man/youtube/blob/master/009/bubble.py,但是在运行以下代码时会出现语法错误;
def sort(arr):
while True:
corrected = False
for i in range(0, len(arr) - 1):
if arr[i] > arr[i+1]:
arr[i], arr[i+1] = arr[i+1], arr[i]
corrected = True
if not corrected:
return arr
# best O(n)
print sort([1, 2, 3, 4, 5, 6])
# average O(n^2)
print sort([4, 2, 3, 1, 6, 5])
# worst O(n^2)
print sort([6, 5, 4, 3, 2, 1])..。结果:
File "test.py", line 13
print sort([1, 2, 3, 4, 5, 6])
^
SyntaxError: invalid syntax有什么建议吗?
发布于 2019-03-04 12:32:30
如果你使用python3
print(sort([...]))你需要加括号。
https://stackoverflow.com/questions/54983296
复制相似问题