pythonic code for bubble sort

This commit is contained in:
Nam Pham
2018-10-30 18:57:29 +07:00
parent 02a67bbb76
commit 17dfd6d1f7
3 changed files with 14 additions and 9 deletions

View File

@ -6,9 +6,7 @@ def bubble_sort(lst):
for passnum in range(len(lst) - 1, 0, -1):
for i in range(passnum):
if lst[i] > lst[i + 1]:
temp = lst[i]
lst[i] = lst[i + 1]
lst[i + 1] = temp
lst[i], lst[i + 1] = lst[i + 1], lst[i]
```

View File

@ -2,6 +2,4 @@ def bubble_sort(lst):
for passnum in range(len(lst) - 1, 0, -1):
for i in range(passnum):
if lst[i] > lst[i + 1]:
temp = lst[i]
lst[i] = lst[i + 1]
lst[i + 1] = temp
lst[i], lst[i + 1] = lst[i + 1], lst[i]

View File

@ -1,6 +1,15 @@
import types,functools
import types
import functools
from pytape import test
from bubble_sort import bubble_sort
def bubble_sort_test(t):
t.true(isinstance(bubble_sort, (types.BuiltinFunctionType, types.FunctionType, functools.partial)),'<util.read_snippets.<locals>.snippet object at 0x7fc8ea4c6978> is a function')
test('Testing bubble_sort',bubble_sort_test)
t.true(
isinstance(bubble_sort, (types.BuiltinFunctionType, types.FunctionType,
functools.partial)),
'<util.read_snippets.<locals>.snippet object at 0x7fc8ea4c6978> is a function'
)
test('Testing bubble_sort', bubble_sort_test)