Question

This function will receive a list of elements with duplicate elements, this function should remove the...

This function will receive a list of elements with duplicate elements, this function should remove the duplicate elements in the list and return a list without duplicate elements. The elements in the returned list must be in the same order that they were found in the list the function received. A duplicate element is an element found more than one time in the specified list.

Homework Answers

Answer #1

PYTHON

def remove_duplicate(A): #define function
    B=[]       #intialize new list B
    for element in A:   #iterate through each element of A
        if element not in B:  #check element exist in new element B if not then append it
            B.append(element)
    print("New list: ",B)
A=[1,1,2,3,3,4,2,6,7,6,8,"A","B","A"]
print("Original list: ",A)
remove_duplicate(A)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write the function has duplicate() which takes as input a vector v and outputs true if...
Write the function has duplicate() which takes as input a vector v and outputs true if there is a re- peated element in v and false if there is no repeated elements. Below is the algorithm which you should implement. default output is 0 for elt1 in v: for elt2 later in v than elt1: if elt1==elt2, make output 1, break, end end end Checking if elt1==elt2 counts as one step. Setting the output value also counts as one step....
A Queue is a linked list with pointers to both the head of the list as...
A Queue is a linked list with pointers to both the head of the list as well as the tail (or the last element) of the list. Given a queue Q, Q.head gives the head of the queue and Q.tail gives the tail of the queue. Give O(1) time algorithms for the following tasks. Enqueue • Input: A queue Q of distinct integers and a queue element a not in Q. 1 • Output: Q with the element a added...
IN SML Write a function dupList of type 'a list -> 'a list whose output list...
IN SML Write a function dupList of type 'a list -> 'a list whose output list is the same as the input list but with each element of the input list repeated twice in a row. For example, if the input is [1, 2, 3], the output list should produce [1, 1, 2, 2, 3, 3]. If the input list [], the output list should be []. Do not use explicit recursion but use one of the fold functions. Do...
using dr.racket programing language If we write a function that tests whether a list contains only...
using dr.racket programing language If we write a function that tests whether a list contains only strings, odd numbers, or even numbers, you will notice that the code that iterates through the list stays the same, with the only change being the predicate function that checks for the desired list element. If we were to write a new function for each of the tests listed above, it would be more error-prone and an example of bad abstraction. We could write...
c) A function named tallied_data() that takes in a nested list (Use this on the data...
c) A function named tallied_data() that takes in a nested list (Use this on the data from part 1, but it should be able to be used to solve similar problems), indices for two columns and returns a tallied list. The inputs are: i) a nested list, ii) an index for the ‘reference column’/ ‘category’ (col_ref) iii) another index for the column to be tallied (col_tally) iv) this function returns a list of tuples where each element is a tuple...
[Python] Write a function named "total_population" that takes a string then a list as parameters where...
[Python] Write a function named "total_population" that takes a string then a list as parameters where the string represents the name of a CSV file containing city data in the format "CountryCode,CityName,Region,Population,Latitude,Longitude" and the second parameter is a list where each element is itself a list containing 3 strings as elements representing the CountryCode, CityName, and Region in this order. Return the total population of all cities in the list. Note that the city must match the country, name, and...
(USING ML) (Using ML) Write a function dupList of type 'a list -> 'a list whose...
(USING ML) (Using ML) Write a function dupList of type 'a list -> 'a list whose output list is the same as the input list but with each element of the input list repeated twice in a row. For example, if the input is [1, 2, 3], the output list should produce [1, 1, 2, 2, 3, 3]. If the input list [], the output list should be []. Do not use explicit recursion but use one of the fold...
Question Recursive Maximum: In this question you must develop and use a recurive function to find...
Question Recursive Maximum: In this question you must develop and use a recurive function to find the maximum value in array of integers. Complete the C program, Maximum.c, by implementing the recursive function maximumValue, and the regular function max, and completing the main function using the comments provided. Open the file Maximum.c, complete, compile and run it. When you are sure it is correct, include the c file in your final submission. Note that the function max is not recursive....
def clear(file_path: str): """ Clears the file at the specified file path. :param file_path: A path...
def clear(file_path: str): """ Clears the file at the specified file path. :param file_path: A path to a file :return: None """ def delete_last_line(file_path: str) -> str: """ Removes the last line in the file at the specified file path. Then it saves the new value with the last line removed to the file. Finally it returns the deleted last line. If the file has nothing in it an empty string ("") is returned. :param file_path: A path to file...
Machine Problem 3 - Linked List C++ For this assignment you will write a program that...
Machine Problem 3 - Linked List C++ For this assignment you will write a program that inserts 20 random integers from 0 to 100 in order in a linked list object. The program will create another linked list, but with 15 random integers from 0 – 100 in order. The program then will merge those two ordered linked list into a single ordered list. The function merge should receive references to each of the list objects to be merged and...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT