Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Exercise 5.7, p. 202 (Duplicate Elimination) - Slightly Modified. Create a function named eliminate_dups that receives a list as a parameter and creates a new
Exercise 5.7, p. 202 (Duplicate Elimination) - Slightly Modified. Create a function named eliminate_dups that receives a list as a parameter and creates a new list that eliminates any duplicate values, returning this (possibly shorter) list containing only the unique values in sorted order. Test your function with the provided list of numbers and list of strings. Hint: Start your function with a new empty list into which you will append values from the list parameter one at a time IF that value isn't already stored in the new list. Use a for loop to step through the values in the parameter list and test if each value is already stored in the new list using keyword in . When the for loop is over, your new list should contain every value in the original parameter list without any duplicates. Return a sorted version of this new list. def eliminate_dups(a_list): \# Put answer here return \# Your sorted newly created list here test_list_1 =[5,7,10,5,7,7,12] test_list_2 =[ 'hi', 'hello', 'hi', 'bye', 'goodbye', 'bye'] test_list_1 =[12,5,7,10,5,7,7] test_list_2 =[ 'hi', 'hello', 'hi', 'bye', 'goodbye', 'bye'] \# Call the function unique_list_1 eliminate_dups(test_list_1) unique_list_2 = eliminate_dups(test_list_2) \#Output results print(f'\{test_list_1\} contains the following unique values:') print(unique_list_1) print(f'\{test_list_2\} contains the following unique values: ') print(unique_list_2)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started