From 17dfd6d1f7617e81c8fb3f4b868ef69e6626a43c Mon Sep 17 00:00:00 2001 From: Nam Pham Date: Tue, 30 Oct 2018 18:57:29 +0700 Subject: [PATCH] pythonic code for bubble sort --- snippets/bubble_sort.md | 4 +--- test/bubble_sort/bubble_sort.py | 4 +--- test/bubble_sort/bubble_sort.test.py | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/snippets/bubble_sort.md b/snippets/bubble_sort.md index 1f81b3324..281d5e554 100644 --- a/snippets/bubble_sort.md +++ b/snippets/bubble_sort.md @@ -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] ``` diff --git a/test/bubble_sort/bubble_sort.py b/test/bubble_sort/bubble_sort.py index c8000f193..48ce048e1 100644 --- a/test/bubble_sort/bubble_sort.py +++ b/test/bubble_sort/bubble_sort.py @@ -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 \ No newline at end of file + lst[i], lst[i + 1] = lst[i + 1], lst[i] diff --git a/test/bubble_sort/bubble_sort.test.py b/test/bubble_sort/bubble_sort.test.py index 08627cfef..139cf6e95 100644 --- a/test/bubble_sort/bubble_sort.test.py +++ b/test/bubble_sort/bubble_sort.test.py @@ -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)),'.snippet object at 0x7fc8ea4c6978> is a function') -test('Testing bubble_sort',bubble_sort_test) \ No newline at end of file + t.true( + isinstance(bubble_sort, (types.BuiltinFunctionType, types.FunctionType, + functools.partial)), + '.snippet object at 0x7fc8ea4c6978> is a function' + ) + + +test('Testing bubble_sort', bubble_sort_test)