Swing list sorting:
Examples:
special_sort(list) -> list
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] # input
[0, 9, 1, 8, 2, 7, 3, 6, 4, 5] # output
def special_sort(list):
r = []
l = len(list)
for i in range(l // 2 + 1):
if i == 0 or (i == l // 2 and not l % 2):
r.append(list[i])
else: r.extend([list[-i], list[i]])
return r
# TODO: Replace examples and use TDD development by writing your own tests
# These are some of the methods available:
# test.expect(boolean, [optional] message)
test.assert_equals(special_sort([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), [0, 9, 1, 8, 2, 7, 3, 6, 4, 5])
test.assert_equals(special_sort([0, 1, 2, 3, 4, 5, 6, 7, 8]), [0, 8, 1, 7, 2, 6, 3, 5, 4])
# test.assert_not_equals(actual, expected, [optional] message)
# You can use Test.describe and Test.it to write BDD style test groupings