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
The 60-watt light bulb has a 400 hour life expectency how much will it cost to operate during its time
expeople1 [14]

Answer:

$2.40

Explanation:

the unit electricity bill is kilo watt hour.

The 60-watt light bulb has a 400 hour life expectency means it will consume

60×400/1000 = 24 KWh units of electricity. Let us suppose each unit of electricity costs is 10 cents.

Then 24×10 = 240 cents  = $2.40

5 0
3 years ago
To quit, a user types 'q'. To continue, a user types any other key. Which expression evaluates to true if a user should continue
devlian [24]

Answer:

!(key == 'q')

Explanation:

Based on the description, the coded expression that would equate to this would be

!(key == 'q')

This piece of code basically states that "if key pressed is not equal to q", this is because the ! symbol represents "not" in programming. Meaning that whatever value the comparison outputs, it is swapped for the opposite. In this case, the user would press anything other than 'q' to continue, this would make the expression output False, but the ! operator makes it output True instead.

3 0
3 years ago
11. Describe an algorithm that interchanges the values of the variables x and y, using only assignments. What is the minimum num
Svetlanka [38]

Answer:

Following is the algorithm to interchange the value of two variable x and y.

step 1:Read the two integer x and y.

step 2 :t=x

Step 3: x=y  

step 4: y=t

The minimum number of assignment to do this is 3

Explanation:

After reading two integer x & y, create a variable "t" of integer type.

with the help of variable "t", we can swap the value of variable x and y.

It requires 3 assignment to interchange the value.

6 0
3 years ago
Access time is:________.
worty [1.4K]

Answer:

B) the time it takes for the required sector to position itself under the read/write head.

Explanation:

In Computer science, Access time is the time it takes for the required sector to position itself under the read/write head. It is usually measured in milliseconds.

It is the speed of the storage device.

5 0
3 years ago
Uso de las redes sociales como el uso de una impresora en casa se satisfacen estás tres etapas
Svetradugi [14.3K]

Question: what question is this?

7 0
3 years ago
Other questions:
  • In Word, tables can be styled much like text can.<br> True<br> False
    6·1 answer
  • Which function should be used to display a value based on a comparison?
    11·1 answer
  • What are the cause of eye strain during computer usage?
    7·1 answer
  • Why you should care about copyright
    13·1 answer
  • The Internet acts as a(n) blank services such as The World Wide Web and email
    6·2 answers
  • How do you change your age on Brainly?
    10·1 answer
  • Consider a multidimensional array A stored in row-major order with 22 rows and 6 columns whose subscripts start at 0. If each el
    8·1 answer
  • Which of the following accessories would you use to create a drawing? A. Calculator B. Notepad C. Paint D. WordPad
    14·2 answers
  • Which function in Excel tells how many
    6·1 answer
  • A large number of genetic codes are stored as binary values in a list. Which one of the following conditions must be true in ord
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!