From 7dcba5ef3b83bd868b23c2ccf0764bbcda37ff28 Mon Sep 17 00:00:00 2001 From: Stephen Date: Thu, 19 Jan 2017 13:29:27 -0600 Subject: [PATCH 1/2] [Python] Challenge 9 (Unreviewed) --- challenge_9/python/slansford/README.md | 5 ++++ challenge_9/python/slansford/README.mdown | 5 ++++ .../python/slansford/src/challenge_9.py | 25 +++++++++++++++++ challenge_9/python/slansford/src/test.py | 28 +++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 challenge_9/python/slansford/README.md create mode 100644 challenge_9/python/slansford/README.mdown create mode 100644 challenge_9/python/slansford/src/challenge_9.py create mode 100644 challenge_9/python/slansford/src/test.py diff --git a/challenge_9/python/slansford/README.md b/challenge_9/python/slansford/README.md new file mode 100644 index 000000000..6074f226e --- /dev/null +++ b/challenge_9/python/slansford/README.md @@ -0,0 +1,5 @@ +Function square_sort in challenge_9.py takes one input, a list with numbers ranging from least to greatest, and may or may not contain positive integers, negative integers, or 0, but will not be empty, and returns an output list of + +Completes unit test in an average of 0.0066 seconds. + +Uses Python 3.6.0 \ No newline at end of file diff --git a/challenge_9/python/slansford/README.mdown b/challenge_9/python/slansford/README.mdown new file mode 100644 index 000000000..6074f226e --- /dev/null +++ b/challenge_9/python/slansford/README.mdown @@ -0,0 +1,5 @@ +Function square_sort in challenge_9.py takes one input, a list with numbers ranging from least to greatest, and may or may not contain positive integers, negative integers, or 0, but will not be empty, and returns an output list of + +Completes unit test in an average of 0.0066 seconds. + +Uses Python 3.6.0 \ No newline at end of file diff --git a/challenge_9/python/slansford/src/challenge_9.py b/challenge_9/python/slansford/src/challenge_9.py new file mode 100644 index 000000000..a873fd3b9 --- /dev/null +++ b/challenge_9/python/slansford/src/challenge_9.py @@ -0,0 +1,25 @@ +def square_sort(inputList): + + pos = [i**2 for i in inputList if i >= 0] + neg = [i**2 for i in inputList if i < 0] + neg = neg[::-1] + + outputList = [] + + while len(outputList) != len(inputList): + + if not neg: + outputList += pos + + elif not pos: + outputList += neg + + elif pos[0] >= neg[0]: + outputList.append(neg[0]) + neg.remove(neg[0]) + + else: + outputList.append(pos[0]) + pos.remove(pos[0]) + + return outputList diff --git a/challenge_9/python/slansford/src/test.py b/challenge_9/python/slansford/src/test.py new file mode 100644 index 000000000..a0d03bddc --- /dev/null +++ b/challenge_9/python/slansford/src/test.py @@ -0,0 +1,28 @@ +import unittest +import time +from challenge_9 import square_sort + + +class Tests(unittest.TestCase): + + def test1(self): + t1 = time.time() + self.assertEqual(square_sort([-3, -2, -1, 0, 1, 2, 3]),[0, 1, 1, 4, 4, 9, 9]) + t2 = time.time() + print('Runtime test1: ' + str(t2-t1)) + + def test2(self): + t1 = time.time() + self.assertEqual(square_sort([4, 5, 6]),[16, 25, 36]) + t2 = time.time() + print('Runtime test1: ' + str(t2-t1)) + + def test3(self): + t1 = time.time() + self.assertEqual(square_sort([-11, -10, -9]),[81, 100, 121]) + t2 = time.time() + print('Runtime test1: ' + str(t2-t1)) + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file From 7b5d719eaefe5c88151ae16ddf58cda4a61573a2 Mon Sep 17 00:00:00 2001 From: slansford Date: Thu, 19 Jan 2017 13:31:18 -0600 Subject: [PATCH 2/2] Delete README.mdown --- challenge_9/python/slansford/README.mdown | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 challenge_9/python/slansford/README.mdown diff --git a/challenge_9/python/slansford/README.mdown b/challenge_9/python/slansford/README.mdown deleted file mode 100644 index 6074f226e..000000000 --- a/challenge_9/python/slansford/README.mdown +++ /dev/null @@ -1,5 +0,0 @@ -Function square_sort in challenge_9.py takes one input, a list with numbers ranging from least to greatest, and may or may not contain positive integers, negative integers, or 0, but will not be empty, and returns an output list of - -Completes unit test in an average of 0.0066 seconds. - -Uses Python 3.6.0 \ No newline at end of file