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
What are the TV resolutions
Leokris [45]
Numbers like 1080p and 4K refer to a TV's<span> screen </span>resolution and<span> the more pixels a screen has the more picture detail it can show.</span>
6 0
3 years ago
If you want to develop an Android app, you need to become a registered developer with which platform?
Orlov [11]
C is the correct answer
3 0
3 years ago
How does communication resolve problems​
Deffense [45]

Answer:

One major benefit effective communication has in resolving a conflict is the resultant reduction in anxiety, whether within a family or in the workplace. ... Using effective verbal – and nonverbal – communications further contributes to a successful resolution of conflict, either between individuals or within a group.

8 0
3 years ago
Read 2 more answers
Jupiter Inc., a software firm, is starting to face competition from the new entrant in its market, Coral Inc. Jupiter wants to p
Scilla [17]

Answer:

A.

Explanation:

Based on the information provided within the question it can be said that in this scenario, Jupiter's best move would be to adopt the measure of ensuring that customers find its software simpler and more convenient to use than that of Coral. This would create satisfaction among the customers which in term would lead to customer loyalty.

8 0
3 years ago
What is the phase shift for the following?A sine wave with zero amplitude after 3/4 cycle and increasing.Show by drawing on grap
frozen [14]

Answer:I think so

Explanation:

7 0
4 years ago
Other questions:
  • In 2-5 paragraphs, describe the points that Kendra needs to consider when choosing a telecommunications technology to meet her n
    6·1 answer
  • Which LOOKUP function will you use if you want to search for a value in the columns?
    5·1 answer
  • What do you think the need for so many different form factors and server types are?
    13·1 answer
  • Which statement below is not true of EFS
    7·2 answers
  • Online retailer Amazon relies heavily on a hierarchy culture to manage its vast and complex shipping processes. ___________ are
    11·1 answer
  • For an alternative to the String class, and so that you can change a String's contents, you can use_________ .
    12·1 answer
  • What is the systems development life cycle (SDLC)? Group of answer choices Involves establishing a high-level plan of the intend
    8·1 answer
  • What is the biggest problem with technology today?
    10·1 answer
  • Question #4
    7·1 answer
  • Adding a border to an image is one way to manipulate media to spice up a project. Where do you find the Picture Styles command t
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!