Python Data Structures Questions Date:14/10/24
List Question 1
Given the list of scores: scores = [85, 92, 78, 95, 88], use Python's built-in functions to find
the highest score.
Real-life application: This can be used in educational platforms to determine the highest
grade in a class.
List Question 2
You have a list of temperatures collected over a week: temperatures = [22.5, 21.0, 23.5, 19.0,
25.0, 24.5, 22.0]. Calculate the average temperature for the week.
Real-life application: This helps in weather monitoring systems to average out weekly
temperatures for climatic studies.
Tuple Question 1
With the tuple dimensions = (8, 10, 12), represent the length, width, and height of a box
respectively, calculate the volume of the box using tuple unpacking.
Real-life application: Useful in logistics and e-commerce to determine packaging dimensions
and shipping requirements.
Tuple Question 2
Given a tuple of names: names = ("Alice", "Bob", "Charlie"), use a Python loop to print each
name on a new line.
Real-life application: This is a common task in software development for processing
multiple items, such as displaying user names or processing data entries.
Set Question 1
You have two sets of product IDs from two sale days: day1 = {101, 102, 103, 104}, day2 =
{103, 104, 105, 106}. Find the IDs of products that were only sold on one of the two days
using set operations.
Real-life application: This operation is crucial in retail analytics to identify exclusive sales
per day.
Set Question 2
For two sets, english = {'John', 'Sarah', 'Charles'} and french = {'Marie', 'Charles', 'Sarah'},
identify the students who are taking both English and French using intersection.
Real-life application: Useful in educational settings to determine cross-enrollment in
language courses.
List and Set Question
You have a list of participants who signed up multiple times for an event: participants =
['Alice', 'Bob', 'Alice', 'Charlie', 'Bob']. Use set operations to list unique participants.
Real-life application: This method is often employed in event management software to clean
up registration lists.
Tuple and List Question
Convert the tuple product_weights = (14, 18, 20, 15) into a list, modify the second item to
19, and convert it back to a tuple.
Real-life application: This could be used in inventory management systems where product
details need to be updated temporarily and then restored.