Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions