Question 1 The purpose of this question is to write a program that grabs a list, recognizes and removes the duplicated i
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Question 1 The purpose of this question is to write a program that grabs a list, recognizes and removes the duplicated i
Question 1 The purpose of this question is to write a program that grabs a list, recognizes and removes the duplicated items. To answer this question, write a function that first ask the user to enter the length of a list. Then, grabs the elements of the list one by one. def grabList(): Afterwards, then write another function that search inside that list element by element and find the duplicated items. def listSearch(): In this function if an element is occurred more than one time, it should be recognized by the program and increase its frequency of occurrence. Basically, in the listSearch() function, a list should be built that each element of that is the frequency of the corresponding element in the output of the grabList() function. In order to remove the duplicated items, write another function: def delDup(): This function will search in the frequency of occurrence of each element and delete the ones that their frequency of occurrence is more than one, meaning removing the item which occurs more than once. For example: list=[1,1,2,3,4,5]→ final list should be equal to [2,3,4,5] All these functions can be called either in a main () function or in a main code body. Note: The code should be able to mention which element(s) was duplicated and remove from the final list. Test your program using different lists with different lengths and elements Enter the length of the list: 4 Enter element 1: 12 Enter element 2:2.4 Enter element 3: a Enter element 4: 2.4 The final list is: [12,a] The element 12 occurs 1 time at 0. The element 2.4 occurs 2 times at 1,3 => it is removed The element a occurs 1 time at 2. Programmed by Stew Dent. Date: Fri Jun 17 08:43:31 2022 End of processing.