Complete the list definition.
user_permissions = 2'Read', 'Write', 'Publish', 'Delete']
Display the first permission in the list.
user_permissions = ['Read', 'Write', 'Publish', 'Delete'] first_permission = user_permissions[''] print(first_permission)
Display the last permission in the list.
user_permissions = ['Read', 'Write', 'Publish', 'Delete'] last_permission = user_permissions[''] print(last_permission)
Display the most expensive item in the list.
item_prices = [10.00, 30.00, 20.90, 5.00, 75.00] most_expensive_item = ''(item_prices) print(most_expensive_item)
What is the output of this code?
product_list = ["Widget A", "Gadget B", "Accessory C", "Tool D", "Equipment E"] product = product_list print(product)
In a customer relationship management system, you have a list of existing customers who made purchases. Now, you want to update the list with new customers from a recent marketing campaign. The new customers are stored in another list. How would you extend the existing customer list with the new customers?
existing_customers = ['Sarah Thompson', 'Daniel Evans', 'Olivia Rodriguez'] new_customers = ['Sophia Lee', 'Matthew Turner'] existing_customers.''(new_customers)
In a project management tool, you have a list of team members assigned to a project. Due to project expansion, you need to add more team members from another project. The additional team members are stored in another list. How would you extend the existing team member list with the new team members?
new_team_members = ['Sophia', 'Daniel', 'Olivia'] existing_team = ['Alex', 'Emily', 'Nathan'] existing_team.extend('')
In a ticket management system, you have a list of unresolved tickets. A new ticket, ‘Ticket 004’, has been received. How would you add ‘Ticket 004’ to the end of the list of unresolved tickets?
unresolved_tickets = ['Ticket 001', 'Ticket 002', 'Ticket 003'] new_ticket = 'Ticket 004' unresolved_tickets.''(new_ticket)
Today is cheat day! Clear all the exercises from the list.
exercises = ["Push-ups", "Sit-ups", "Jumping jacks"] exercises.''()
In an inventory management system, you have a list of products representing the available inventory. As customers make purchases, you need to remove the sold products from the list. Additionally, you want to keep track of the last sold product. How would you remove a specific product from the list and retrieve the last sold product?
# Create a list of products representing the available inventory inventory = ['Product 1', 'Product 2', 'Product 3', 'Product 4'] # Remove and retrieve the sold product sold_product = inventory.''(2) print(sold_product)
In an employee onboarding system, you need to create a list to store the names of newly hired employees. Initially, the list is empty. As new employees join the company, their names will be added to the list. How would you create an empty list ?
# Create an empty list to store employee names newly_hired_employees = '' # Get the names of three newly hired employees employee_name_1 = input("Enter the name of the first newly hired employee: ") employee_name_2 = input("Enter the name of the second newly hired employee: ") employee_name_3 = input("Enter the name of the third newly hired employee: ") # Add the employee names to the list newly_hired_employees.append(employee_name_1) newly_hired_employees.append(employee_name_2) newly_hired_employees.append(employee_name_3) print(newly_hired_employees)
In a customer support system, you have a list of open tickets representing customer issues. As support agents resolve these issues, you need to remove the corresponding tickets from the list. How would you remove a specific ticket from the list?
# Create a list of open tickets open_tickets = ["Ticket 1", "Ticket 2", "Ticket 3", "Ticket 4"] # Assume Ticket 3 has been resolved and needs to be removed resolved_ticket = "Ticket 3" # Remove the resolved ticket from the list open_tickets.''(resolved_ticket)
Python Exercises for Data Structures
If you’ve faced difficulties with these exercises, take a look at Data Structures Module on my Python course.
You can also share ‘Python Data Structures’ Exercises on your:
X (Twitter) – Telegram – Linkedin – Facebook – or on your favorite platform…