1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
yan [13]
3 years ago
9

Write a function named remove_duplicates that takes a list (of numeric and/or string values) and returns a new list with only th

e unique elements from the original. This function assumes that there is at least 1 element in the list and that the list does not contain any sublists. The original list is not modified in any way. The returned list does not have to preserve the order of the original list.
Computers and Technology
1 answer:
Lorico [155]3 years ago
6 0

Answer:

def remove_duplicates(lst):

   no_duplicate = []

   dup = []

   for x in lst:

       if x not in no_duplicate:

           no_duplicate.append(x)

       else:

           dup.append(x)

   for y in dup:

       if y in no_duplicate:

           no_duplicate.remove(y)

   return no_duplicate

Explanation:

Create a function called remove_duplicates that takes one parameter, lst

Create two lists one for no duplicate elements and one for duplicate elements

Create for loop that iterates through the lst. If an element is reached for first time, put it to the no_duplicate. If it is reached more than once, put it to the dup.

When the first loop is done, create another for loop that iterates through the dup. If one element in no_duplicate is in the dup, that means it is a duplicate, remove that element from the no_duplicate.

When the second loop is done, return the no_duplicate

You might be interested in
Please help, I can't find the answer but I understand the topic.
gladu [14]

Answer:

x=(2+3)*3;

Explanation:

3 0
3 years ago
Read 2 more answers
.9 What is Artificial Intelligence?
Serhud [2]
C because bread is not happy with you
8 0
3 years ago
Given an array temps of double s, containing temperature data, compute the average temperature. Store the average in a variable
Ket [755]

Answer:

#include <iostream>

using namespace std;

// average function

void average(double arr[], int n) {

double total = 0;

double avgTemp;

for (int i = 0; i < n; i++)

{

 // find temperatures total

 total = total + arr[i];

}

// find average

avgTemp = total / n;

cout << "\nAverage Temperature = " << avgTemp << endl;

}

// print temps[] array

void printArray(double arr[], int n) {

for (int i = 0; i < n; i++)

{

 cout << arr[i] << "   ";

}

}

int main() {

int const k = 5;

double temps[k];

// temperature value

double tempValue;  

// Enter 5 temperatures of your choice

for (int i = 0; i < k; i++)

{

 cout << "Enter Temperature value " << i+1 << ": ";

 cin >> tempValue;

 temps[i] = tempValue;

}

// Function call to print temps[] array

printArray(temps, k);  

// Function call to print average of given teperatures

average(temps, k);        

return 0;

}

Explanation:

• Inside main(), int constant k is created to set the maximum size of array temps[].

• tempValue of  type double takes value at a given index of our temps[] array.

• the for loop inside main() is used to get tempValue from the user and store those values in our array temps[].

• after that printArray() function is called. to pass an array to a function it requires to perimeters 1) name of the array which is temps in our case. 2) maximum number of the index which is  k.

• note the syntax of void average(double arr[], int n). Since we are passing an array to the function so its formal parameters would be arr[] and an int n which specifies the maximum size of our array temps[].

6 0
3 years ago
Which of the following sorting algorithms is described by this text? "Take the item at index 1 and see if it is in order compare
trasher [3.6K]

Answer:

b. selection sort

b. 8 11 17 30 20 25

Explanation:

The options above are the correct answers to the given questions.

Selection sort is a simple comparison-based sorting algorithm.

selection sort. (algorithm) Definition: A sort algorithm that repeatedly searches remaining items to find the least one and moves it to its final location. The run time is Θ(n²), where n is the number of elements. The number of swaps is O(n).

It is this sorting algorithm that will best ne suitable in the given event.

7 0
3 years ago
vertical exchanges are typically used only to buy and sell materials required for an organization's support activities ( True or
torisob [31]

Answer:

Vertical exchanges are typically used only to buy and sell materials required for an organization's support activities- False

7 0
2 years ago
Read 2 more answers
Other questions:
  • Terrence smiles at his customers, helps his coworkers, and stays late when needed. What personal skill does Terrence demonstrate
    10·2 answers
  • You're the network administrator for a company that has just expanded from one floor to two floors of a large building, and the
    7·1 answer
  • A coworker asks your opinion about how to minimize ActiveX attacks while she browses the Internet using Internet Explorer. The c
    10·1 answer
  • True / False<br> An instruction’s opcode generally indicates the number and type of its operands.
    5·1 answer
  • Choose the type of error described.
    12·1 answer
  • What usually happens during the investigation &amp; analysis stage of the Systems Life Cycle
    15·1 answer
  • I need help!!!! 1.04
    9·1 answer
  • What is a trojan horse
    8·2 answers
  • Creating a wedding website on the knot- how to make the text wide
    15·1 answer
  • In cyber security, one of the best ways to protect a computer or network is with a strategy called defense in depth. This strate
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!