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
Microsoft Paint can be described as a digital sketch pad ?
alexira [117]
Yes I can be be a digital sketch pad

HOPE THIS HELPS!!!!!!!
4 0
3 years ago
ENG103 DISCUSSION BOARD 6
amm1812
The proper citation for your course of study -computer related- is APA (American Psychological Association)  format. This citation format allows us to state the publication date, title , and authors in an organized and short fashion. All scholarly reports that are technology or psychology based, should be cited in APA format. 

<span>I know this because it is the format I use for all of my college courses which are all Computer/Technology related. </span>
3 0
3 years ago
____ can help you determine whether a network is truly under attack or a user has inadvertently installed an untested patch or c
FinnZ [79.3K]

Answer:

Network forensics

Explanation:

hide the most valuable data at the innermost part of the network.

5 0
2 years ago
What type of error results from an error in the formatting of the program code?
NNADVOKAT [17]
I believe the answer is a syntax error. For example, in java if a semicolon is missed, a syntax error will be produced because the code cannot compile.
5 0
3 years ago
In a C++ program, one and two are double variables and input values are 10.5 and 30.6. After the statement cin &gt;&gt; one &gt;
SSSSS [86.1K]

Answer:

variable one stores 10.5 and two stores 30.6

Explanation:

In c++ language, the cout keyword is used to write to the standard output. The input from the user is taken by using the cin keyword.

For the input from the user, a variable need is declared first.

datatype variable_name;

The input can be taken one at a time as shown.

cin >> variable_name;

The input for more than one variable can be taken in a single line as given by the syntax below.

1. First, two variables are declared.

datatype variable_name1, variable_name2;

2. Both input is taken simultaneously as shown.

cin >> variable_name1, variable_name2;

For the given scenario, two double variables are declared as below.

double one, two;

The question mentions input values for the two double variables as 10.5 and 30.6.

3. The given scenario takes both the values as input at the same time, in a single line as shown below.

cin >> one >> two;

4. After this statement, both the values entered by the user are accepted.

The values should be separated by space.

First value is stored in the variable one.

Second value is stored in the variable two.

5. The user enters the values as follows.

10.5 30.6

6. The value 10.5 is stored in variable one.

7. The value 30.6 is stored in variable two.

The c++ program to implement the above is given below.

#include <iostream>

using namespace std;

int main() {

   double one, two;      

   cout << " Enter two decimal values " << endl;

   cin >> one >> two;

   cout << " The input values are " << endl;

   cout << " one : " << one << " \t " << " two : " << two << endl;

   return 0;

}

OUTPUT

Enter two decimal values  

10.5 30.6

The input values are  

one : 10    two : 530.6

6 0
3 years ago
Other questions:
  • Is this picture the CPU, RAM, CD, or Operating System
    15·1 answer
  • Where can the Ease of Access and Speech Recognition centers be found?
    8·2 answers
  • Select all that apply. To assist in document sharing, you should?
    12·2 answers
  • Which components can be added to a lightning app on custom object (choose 3 answers)A. Visualforce B. Standard Lightning compone
    6·1 answer
  • Which of the following clauses of the UPDATE command is optional? (Points : 2) UPDATE
    11·1 answer
  • What is a goal?
    13·1 answer
  • There are some network modeling tools that can ________ the existing network.
    12·2 answers
  • What is output? Select all that apply. c = 3 while (c &lt; 10): c = c + 2 print (c)
    6·1 answer
  • Which graphic file format is used for commercial purposes.
    10·1 answer
  • What made the master so angry with his servant?​
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!