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
Rufina [12.5K]
3 years ago
6

Implement the function unique that takes as a parameter a two-dimensional list and returns a one-dimensional list containing all

the unique entries in the list. The entries in the list returned do not need to be ordered in any particular way. For example, in the list [[1, 0, 1], [0, 1, 0]] there are only two unique values (0 and 1) so the function would return the list [0, 1] (or the list [1, 0] -- both are valid). The list passed as a parameter should not be altered by the function
Computers and Technology
1 answer:
Airida [17]3 years ago
7 0
<h2>Answer:</h2>

#Method definition for the function unique()

#The method takes in one argument which is a two dimensional list

def unique (twoDList) :

   #Create an empty one dimensional list

   oneDList = [];

   

   #Convert the two dimensional list to a one dimensional list by

   #looping through the two dimensional list and putting each element in

   # the one dimensional list using the python in-built append() function

   for i in range(len(twoDList)) :  

        for j in range(len(twoDList[i])) :  

           oneDList.append(twoDList[i][j])

   

   #Convert the one dimensional list to a set to make the list unique

   #by using the python in-built set() function

   mySet = set(oneDList)

   #Convert the unique list back to a list

   uniqueList = list(mySet)

   #Return the unique list

   return uniqueList

#End of method declaration

#Call the method with an arbitrary two dimensional list, and print the result

print(unique([[3,5,3],[4,6,3],[1,7,8]]))

print(unique([[1, 0, 1], [0, 1, 0]]))

<h2>Output</h2>

=================================================================

[1, 3, 4, 5, 6, 7, 8]

[0,1]

================================================================

<h2>Explanation:</h2>

The above code has been written in Python. It contains comments explaining each line of the code. Please go through the comment. The actual code has been written in bold-face to differentiate it from comments. Note that in Python, indentation really matters. Therefore, the code must be written with the appropriate indentations like those shown in the code above.

For clarity, the code is re-written as follows without comments.

def unique (twoDList) :

   oneDList = [];

   for i in range(len(twoDList)) :  

        for j in range(len(twoDList[i])) :  

           oneDList.append(twoDList[i][j])

   mySet = set(oneDList)

   uniqueList = list(mySet)

   return uniqueList

print(unique([[3,5,3],[4,6,3],[1,7,8]]))

print(unique([[1, 0, 1], [0, 1, 0]]))

You might be interested in
Drag the tiles to the correct boxes to complete the pairs.
goldenfox [79]

Answer:

Emphasis pattern movement

3 0
3 years ago
Read 2 more answers
What is a statement that runs only under counting conditions?
IRINA_888 [86]

Answer:

An if statement

Explanation:

An if statement runs provided the logical requirement is satisfied.

7 0
3 years ago
2Discuss the difference between overriding and overloading. (This is a very common interview question in programming)
nordsb [41]

Explanation:

Following are the difference between overriding and overloading

(1) Method overloading means method having same name but different parameter or method signature Whereas  Method overriding means method having same name and same parameter or signature.

(2) Method overloading is achieved the compile time Polymorphism whereas Method overriding is achieved the Run time Polymorphism .

(3 ) In method overriding child class have facility to provide a specific implementation of a method which is already defined by parent class method whereas there is no such facility is available in method overloading

(4 )Programming structure of method overloading

class test

{

 void fun()

{

// statement

}

void fun(int b)

{

// statement

}

}

In this fun() method name is same but different signature I.e void fun() and void fun(int a);  

Programming structure of method overriding  

class parent

{

  void fun()

{

// statement in parent class

}

}

class child extends test

{

void fun()

{

// override the statement in child class

}

}

In this fun() method have same name and same signature in both class  

7 0
3 years ago
Return true if the given non-negative number is a multiple of 3 or 5, but not both. Use the % "mod" operator.
Pani-rosa [81]

the following C++ function will return true if the given non - negative number is multiple of 5 or 3 else it will return false.

bool function( int x ){

// variable to check if it is multiple of both or not

int number =0;

if(3%x == 0){

number++;

}

if(5%x == 0){

number++;

}

// Now returning by deciding

if( number <=1)

return true;

else

return false

}

4 0
4 years ago
A ball is released from a 10 m high roof and bounces two thirds as high on each successive bounce. After traveling a total of 40
skelet666 [1.2K]

Answer:

Four times traveling 40,12345 mts

Explanation:

We can express this as a sum as follows

\sum_{i=1}^4(10\cdot  \frac{2}{3}^{i - 1} + 10\cdot  \frac{2}{3}^{i } ) = 3250/81=40.12345679

The first term is the dropping part and the second is the upward motion. this sums up to 40,12345 m after bouncing four times. As a program we could write using the while loop.

distance=0;

i:=0;

while distance<40 do

i:=i+1;

distance:=distance+ 10\cdot  \frac{2}{3}^{i - 1} + 10\cdot  \frac{2}{3}^{i };

end while;

Here the answer is in i and the closest distance traveled after reaching 40 is in the variable distance.

4 0
4 years ago
Other questions:
  • Some might consider careers in the Construction industry to be quite flexible. Which statement supports this claim? Employees ca
    14·2 answers
  • Elaine works in a production house, and she determines the visual aspects of films and television. what is her profession?
    8·1 answer
  • Jim maintains attendance records for his employees for the year. Row B includes the dates of attendance, and column A includes t
    5·2 answers
  • Xavier would like to change the sort options for his contacts. In which tab will he find the Arrangement command group?
    6·1 answer
  • my pc wants to run the highest graphics even though I restart it everyday and it gets around 10 fps and I have a 1080 Nvidia gra
    7·1 answer
  • Post as a reply your example of "data, which is processed into information" case - examples should not necessarily be related to
    13·1 answer
  • Television is a technological development that occurred during the what age?
    5·1 answer
  • Which statement compares the Autofill and Flash Fill features?
    9·2 answers
  • When converting text to a table, which feature should be used?
    12·1 answer
  • What's the use of computer?Where are they used?​
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!