Python Collections Challenge: Lists, Tuples, Sets, and Dictionaries
Python Collections Challenge: Lists, Tuples, Sets, and Dictionaries Data Science Project
Python Collections

Python Collections Challenge: Lists, Tuples, Sets, and Dictionaries

This Knowledge Quiz covers Python collections (lists, tuples, sets, dictionaries) and how to use them together, including operations on them through nesting and combining. Through scenario-based questions related to Python collections, you will develop an in-depth understanding of these topics.
Start this project
Python Collections Challenge: Lists, Tuples, Sets, and DictionariesPython Collections Challenge: Lists, Tuples, Sets, and Dictionaries
Project Created by

Anurag Verma

Project Activities

All our Data Science projects include bite-sized activities to test your knowledge and practice in an environment with constant feedback.

All our activities include solutions with explanations on how they work and why we chose them.

codevalidated

Extracting Insights from Customer Data

Suppose you have a list of dictionaries, where each dictionary represents a customer's data. Each dictionary has the following keys: name, age, orders. The orders key contains a list of order IDs.

customer_data = [
    {'name': 'Alice', 'age': 30, 'orders': [101, 103, 105]},
    {'name': 'Bob', 'age': 25, 'orders': [102, 104]},
    {'name': 'Charlie', 'age': 28, 'orders': [106]}
]

Write a function get_total_orders(customer_list) that takes the customer_data list as a parameter and returns the total number of orders across all customers.

You have to write the function in the input box below.

multiplechoice

Temperature Data Mapping

A compilation of temperature readings over a week is provided. Each temperature corresponds to a specific day.

temperature_data = [72, 75, 68, 70, 74, 79, 81]
days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

Expected result looks like below:

temperature_dict = {
    'Monday': 72,
    'Tuesday': 75,
    'Wednesday': 68,
    'Thursday': 70,
    'Friday': 74,
    'Saturday': 79,
    'Sunday': 81
}

Select the appropriate option that generates a dictionary named temperature_dict, associating each day with its respective temperature.

codevalidated

Inventory Revenue Calculation

The inventory of a grocery store is being managed. Each product is represented as a dictionary containing keys product_id, name, quantity, and price.

inventory = [
    {'product_id': 101, 'name': 'Apple', 'quantity': 50, 'price': 0.5},
    {'product_id': 102, 'name': 'Banana', 'quantity': 30, 'price': 0.3},
    {'product_id': 103, 'name': 'Orange', 'quantity': 40, 'price': 0.4}
]

Craft a function named calculate_total_revenue(inventory) that computes the overall revenue generated by the products in the inventory.

multiplechoice

Social Media Engagement Rate

Information regarding user interaction with posts on a social media platform is available. Each post is represented as a dictionary containing post_id, likes, comments, and shares

post_data = [
    {'post_id': 101, 'likes': 50, 'comments': 12, 'shares': 5},
    {'post_id': 102, 'likes': 75, 'comments': 8, 'shares': 10},
    {'post_id': 103, 'likes': 30, 'comments': 5, 'shares': 2}
]

Opt for the accurate function calculate_engagement_rate(posts) that evaluates the mean engagement rate across all posts. The engagement rate is defined as the total sum of likes, comments, and shares divided by the total number of posts.

multiplechoice

Shared Course Enrollments

The task involves overseeing student course enrollments. Each student's information is captured using a dictionary with student_id, name, and courses attributes. The courses attribute contains a set of course IDs.

students = [
    {'student_id': 1, 'name': 'Alice', 'courses': {101, 103, 105}},
    {'student_id': 2, 'name': 'Bob', 'courses': {102, 104}},
    {'student_id': 3, 'name': 'Charlie', 'courses': {106}}
]

Indicate the appropriate choice for a function find_common_courses(students) that produces a set of course IDs in which at least two students are enrolled.

multiplechoice

Duplicate Data Check

The objective is to assess a list of data entries and identify any duplications.

data_entries = ['apple', 'banana', 'orange', 'apple', 'grape', 'banana']

Select the appropriate options that effectively eliminate duplicate entries from the data_entries list.

multiplechoice

Student Exam Scores

A compilation of student names and their respective exam scores is provided.

students = ['Alice', 'Bob', 'Charlie', 'David']
scores = [85, 92, 78, 95]

Choose the accurate options that lead to the creation of a dictionary in which student names function as keys and exam scores function as values.

multiplechoice

Employee Count by Department

A roster of employee names and their respective departments is available. The objective is to calculate the employee count within each department.

employees = ['Alice', 'Bob', 'Charlie', 'David', 'Eva']
departments = ['HR', 'Finance', 'IT', 'IT', 'HR']

Select the accurate options that lead to the creation of a dictionary where departments function as keys and the count of employees in each department serves as the value.

multiplechoice

Shopping Cart Total

A collection of items within a shopping cart and their associated prices is at your disposal.

items = ['Apple', 'Banana', 'Orange']
prices = [1.0, 0.5, 0.75]
quantities = [3, 2, 4]

Choose the accurate options that perform calculations resulting in the determination of the total cost of the items present in the shopping cart.

multiplechoice

Word Frequency Counter

You are analyzing the frequency of words in a text document. You have a list of words.

words = ['hello', 'world', 'hello', 'python', 'world']

Select all correct option that create a dictionary where words are keys and their frequencies are values.

multiplechoice

Matrix Transposition

You have a matrix represented as a list of lists, and you want to transpose it.

matrix = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
]

Choose all the correct option which transpose the given matrix.

multiplechoice

Nested Dictionary Manipulation

A nested dictionary is employed to capture student information, encompassing name, age, and grades.

students = {
    'Alice': {'age': 20, 'grades': [85, 92, 78]},
    'Bob': {'age': 21, 'grades': [92, 88, 90]},
    'Charlie': {'age': 19, 'grades': [78, 80, 75]}
}

Choose the appropriate options that execute the computation of the average grade for each student and subsequently organize this data within a new dictionary.

The resultant structure is as follows:

average_grades = {
    'Alice': 85.0,
    'Bob': 90.0,
    'Charlie': 77.66666666666667
}
multiplechoice

User Message Summary

You're a Data Scientist at Slack, and your task is to process messages for conversations between users. The messages are given in the format of a list of dictionaries.

messages = [
    {'from': 'santiago', 'to': 'anurag', 'message': 'Hello world', 'is_read': False},
    {'from': 'martin', 'to': 'santiago', 'message': 'How are you', 'is_read': False},
    # ...
]

Your goal is to generate a summary for each user that includes the total number of messages and the number of unread messages they have received. Which code correctly generates the desired summary?

The generated summary looks like below:

summary = {
    'santiago': {'total': 2, 'unread': 2},
    'anurag': {'total': 1, 'unread': 1},
    'martin': {'total': 1, 'unread': 1}
}
codevalidated

Employee Salary Calculation

You are working on a payroll system to calculate employee salaries. Each employee's information is represented as a dictionary with employee_id, name, hours_worked, and hourly_rate keys.

employees = [
    {'employee_id': 101, 'name': 'Alice', 'hours_worked': 40, 'hourly_rate': 20},
    {'employee_id': 102, 'name': 'Bob', 'hours_worked': 35, 'hourly_rate': 18},
    {'employee_id': 103, 'name': 'Charlie', 'hours_worked': 45, 'hourly_rate': 22}
]

Complete the below solution to calculate the correct salaries of each employee.

salaries = {}
for employee in employees:
    employee_id = employee['employee_id']
    salary = ... # Calculate correct salary
    salaries[employee_id] = salary

Calculated salaries look like below:

salaries = {
    101: 800,
    102: 630,
    103: 990
}
codevalidated

Task Completion Progress

You are tracking the progress of tasks in a project. Each task's information is represented as a dictionary with task_id, description, status, and completed_percent keys.

tasks = [
    {'task_id': 1, 'description': 'Design', 'status': 'In Progress', 'completed_percent': 30},
    {'task_id': 2, 'description': 'Development', 'status': 'In Progress', 'completed_percent': 50},
    {'task_id': 3, 'description': 'Testing', 'status': 'Completed', 'completed_percent': 100}
]

Identify and correct the mistake in the provided below solution to properly identify incomplete tasks that are in progress.

incomplete_tasks = []
for task in tasks:
    if task['status'] == 'In Progress' and task['completed_percent'] != 100:
        incomplete_tasks.append(task['description'])
codevalidated

User Activity Tracking

You are analyzing user activity data for a social media platform. Each user's activity is represented as a dictionary with user_id, posts, likes, and comments keys.

user_activity = [
    {'user_id': 101, 'posts': 5, 'likes': 20, 'comments': 10},
    {'user_id': 102, 'posts': 3, 'likes': 15, 'comments': 5},
    {'user_id': 103, 'posts': 8, 'likes': 25, 'comments': 15}
]

Write code to calculate the total engagement (likes + comments) for each user and store it in a new dictionary named user_engagement.

Output look like below:

user_engagement = {
    101: 30,
    102: 20,
    103: 40
}
multiplechoice

User Account Management

You are building a user account management system. Each user's account information is represented as a dictionary with user_id, username, email, and is_active keys.

user_accounts = [
    {'user_id': 101, 'username': 'alice123', 'email': 'alice@example.com', 'is_active': True},
    {'user_id': 102, 'username': 'bob456', 'email': 'bob@example.com', 'is_active': False},
    {'user_id': 103, 'username': 'charlie789', 'email': 'charlie@example.com', 'is_active': True}
]

Choose correct option that create a list of usernames for active users.

The expected list looks like below:

active_usernames = ['alice123', 'charlie789']
multiplechoice

Product Inventory

ou are managing a product inventory for an online store. Each product's information is represented as a dictionary with product_id, name, price, and quantity keys.

products = [
    {'product_id': 1, 'name': 'Laptop', 'price': 1000, 'quantity': 10},
    {'product_id': 2, 'name': 'Phone', 'price': 800, 'quantity': 15},
    {'product_id': 3, 'name': 'Tablet', 'price': 400, 'quantity': 20}
]

Choose correct option that calculate the total value of the inventory (sum of price * quantity for each product).

Python Collections Challenge: Lists, Tuples, Sets, and DictionariesPython Collections Challenge: Lists, Tuples, Sets, and Dictionaries
Project Created by

Anurag Verma

What's up, friends! 👋 I'm a computer science student about to finish my last year of college. 🎓 I LOVE writing code! ❤️ It makes me so happy! 😄 Whether I'm goofing in notebooks 📓 or coding in Python 🐍, writing programs is a blast! 💥

What's up, friends! 👋 I'm a computer science student about to finish my last year of college. 🎓 I LOVE writing code! ❤️ It makes me so happy! 😄 Whether I'm goofing in notebooks 📓 or coding in Python 🐍, writing programs is a blast! 💥

This project is part of

Python Collections

Explore other projects