Question: Create a file named sorting.py that provides two functions: swap and sort _ short. swap The swap function must take three arguments: a list, and
Create a file named sorting.py that provides two functions: swap and sortshort.
swap
The swap function must take three arguments: a list, and two integers representing indices into the list. It must then swap the the list elements stored at the provided indices. It should not have any return value.
Here is an example of the expected behavior:
items abc
swapitems
printitems
cba
sortshort
The sortshort function must take a single list argument containing numeric values. The list will have no more than three items. This function must rearrange the items in the list so that they appear in increasing order. Your implementation should call the swap method as needed to move items within the list. For example, if we knew that the list would have exactly two items, the following implementation would be correct:
def sortshortitems:
if items items:
swapitems
There is no return value. You may assume that the list will not contain duplicates.
Here is an example illustrating how we can use the assert statement to check for the correct behavior:
if namemain:
items
sortshortitems
assert items
items
sortshortitems
assert items
items
sortshortitems
assert items
The assert statement provides a builtin mechanism for confirming that our code is working as expected. If the expression after assert evaluates to True, then nothing happens, if it evaluates to False, then there will be an AssertionError indicating that there is something wrong with our implementation or with our test
Your solution must not use any loops, and it must not use any builtin sorting functions.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
