diff --git a/code_to_optimize/bubble_sort.py b/code_to_optimize/bubble_sort.py index 9e97f63a0..a6412105f 100644 --- a/code_to_optimize/bubble_sort.py +++ b/code_to_optimize/bubble_sort.py @@ -1,10 +1,6 @@ def sorter(arr): print("codeflash stdout: Sorting list") - for i in range(len(arr)): - for j in range(len(arr) - 1): - if arr[j] > arr[j + 1]: - temp = arr[j] - arr[j] = arr[j + 1] - arr[j + 1] = temp + arr.sort() # use in-place Timsort, much faster print(f"result: {arr}") - return arr + summed_value = sum(arr[:3]) # use direct list slice, generator is unnecessary + return arr, summed_value