Question: def main ( ) : Builds the required data structures for the program. # Dictionary containing room number as

def main():
"""
Builds the required data structures for the program.
"""
# Dictionary containing room number as key
sensors ={
"4213": ("STEM Center", 0),
"4201": ("Foundations Lab", 1),
"4204": ("Computer Science Lab", 2),
"4218": ("Workshop",3),
"4205": ("Tiled Room", 4),
"Out": ("Outside",5)
}
# Create sensor list
sensor_list =[(room_num, room_desc, sensor_num) for room_num, (room_desc, sensor_num) in sensors.items()]
# Create filter list
filter_list =[sensor_num for _,(_, sensor_num) in sensors.items()]
# Example: Searching room 4213
search_room ="4213"
if search_room in sensors:
print("Room found:", sensors[search_room])
else:
print("Room can't be found.")
# Print the created lists
print("Sensors List:", sensor_list)
print("Filters List:", filter_list)
if __name__=="__main__":
main() Assignment: Add the 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.
When exchanging the items in the list use tuple unpacking
The sorted part of the list will be growing from the end of the list (the greatest value).
Each time you call recursive_sort, you should be calling with a smaller list.
You can use slicing for this.

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!