Question: This is just not the way to do this I have tried to make your assignments so far as real-world as possible. The final project

This is just not the way to do this

I have tried to make your assignments so far as real-world as possible. The final project we come up with could actually be useful for, say, a STEM Center director, and along the way we've covered the required material for the class.

This assignment is a little contrived, though. Meaning, we could do this more easily and more efficiently - but this assignment will help you understand how sorts and recursions work.

It is important to understand recursion, but recursion is expensive in terms of both memory and processing time. So, if there's an easy way to do a task directly, it's probably best to avoid recursion. Unless you are doing this assignment.

And, it's important to understand sorts. Believe it or not, a LOT of research has been done about sorting algorithms in the last century or so. Bubble sort is easy to understand, but there are other sorts that are much faster. You will learn about them in your algorithms class.

So here we are, implementing a bubble sort with recursion. It's okay, we have a very small amount of data to sort. And I guarantee you will be challenged with this assignment.

The Program Spec

Create a function recursive_sort() which has as its parameters, list_to_sort (a list of tuples like the one you just made) and key. key should have a default value of zero, and refers to whether the list should be sorted by the first or second value in the tuple. Of course, recursive_sort() should call itself as part of the process.

The sorted part of the list will be growing from the end of the list. Each time you call recursive_sort, you should be calling with a smaller list. You can use slicing for this.

For example, suppose you were sorting this list:

list = [5,4,1,2,3]

after the first pass your list would look like this. The five at the end won't change after this pass, it's in its correct position.

[4,1,2,3,5]

For the next pass, just pass the first four elements, or list[0:4] . After sorting, the list looks like this:

[1,2,3,4,5]

Your list is sorted, but the program doesn't know that. It only knows for sure that the last two elements are sorted. So pass list[0:3]

You might create some code in your algorithm to recognize when no flips are made in a particular pass. In this case, the program knows that the list is sorted and can end. It's also okay (but not as efficient) to continue passing the list through the recursion until there is only one item left to pass.

If you are struggling to get the logic right, try printing out the list inside the function you are creating, to see how it changes.

Remember the unit test code I gave you for the last assignment? We don't need that anymore, please replace it with these lines:

print(sensor_list) print(recursive_sort(sensor_list, 0)) print(recursive_sort(sensor_list, 1)) print(sensor_list)

The first four lines of your run should look exactly like those in the run below. Notice that the original list remains in its original order.

[('4213', 'STEM Center', 0), ('4201', 'Foundations Lab', 1), ('4204', 'CS Lab', 2), ('4218', 'Workshop Room', 3), ('4205', 'Tiled Room', 4), ('Out', 'Outside', 5)] [('4201', 'Foundations Lab', 1), ('4204', 'CS Lab', 2), ('4205', 'Tiled Room', 4), ('4213', 'STEM Center', 0), ('4218', 'Workshop Room', 3), ('Out', 'Outside', 5)] [('4204', 'CS Lab', 2), ('4201', 'Foundations Lab', 1), ('Out', 'Outside', 5), ('4213', 'STEM Center', 0), ('4205', 'Tiled Room', 4), ('4218', 'Workshop Room', 3)] [('4213', 'STEM Center', 0), ('4201', 'Foundations Lab', 1), ('4204', 'CS Lab', 2), ('4218', 'Workshop Room', 3), ('4205', 'Tiled Room', 4), ('Out', 'Outside', 5)] STEM Center Temperature Project Eric Reed Main Menu --------- 1 - Process a new data file 2 - Choose units 3 - Edit room filter 4 - Show summary statistics 5 - Show temperature by date and time 6 - Show histogram of temperatures 7 - Quit What is your choice? 7 Thank you for using the STEM Center Temperature Project Process finished with exit code 0

This should be done in Python

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!