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
slava [35]
3 years ago
13

Please do in python.Given an array of integers, create a 2-dimensional array where the first element is a distinct value from th

e array and the second element is the value’s frequency within the array. Sort the resulting array descending by frequency. If multiple values have the same frequency, they should be sorted ascending.Example: arr = [3,3,1,2,1]There are two values, 3&1 each within frequency of 2, and one value 2 with a frequency of 1: [[3,2], [1,2], [2,1]] Sort the 2-dimensional descending by frequency: [[3,2], [1,2], [2,1]] Sort the 2-dimensional array descending by values with matching frequencies [[1,2], [3,2], [2,1]]
Computers and Technology
1 answer:
VladimirAG [237]3 years ago
5 0

Following are the Python program to sort the 2-dimensional array in descending order.

Program Explanation:

  • Defining a list "arr" that holds an integer value.
  • Defining multiple empty lists "m,n, and o".
  • In the next step, a for loop is declared that defines an if block that uses an append method to add value into the list.
  • Inside this, "m" variable that sort by frequency of array, and declared two for loop with the if conditional block.
  • In this, it sorts array and store its value with the "m" and print its value.

Program:

arr=[3,3,1,2,1]#defining a list  

m=[] #defining an empty list m  

n=[] #defining an empty list n  

o=[]#defining an empty list o  

for i in arr: #defining a for loop that iterate arr

 if i not in o: # defining if block that add value in empty list  

   n.append(i)#using append method to add value

   n.append(arr.count(i))#using append method add its index value

   m.append(n) #element and its frequency storeds in 2d matrix

   n=[]#defining an empty list n

   o.append(i)#calling append method to add value

m=sorted(m,key=lambda l:l[1], reverse=True) # defining m variable that sort by frequency of array

# sort by element

for i in range(len(m)):#using loop variable i that takes m matrix length

 for j in range(len(m)):#using loop variable j that takes m matrix length

   if m[i][0]<m[j][0] and m[i][1]==m[j][1]:#using if block that sort array element

     m[i],m[j]=m[j],m[i]#defining matrix that hold matrix value  

print(m) #print matrix value

Output:

Please find the attached file.

Learn more:

brainly.com/question/12286809

You might be interested in
Do you watch markiplier?
ki77a [65]

Answer: Yes

Explanation: He is cool

5 0
3 years ago
Read 2 more answers
Technician A says that a lead acid battery uses straight Hydrochloric acid for electrolyte. Technician B says that a lead acid b
konstantin123 [22]

Technician B is correct

It is safe to say that Lead acid uses sulfuric acid. When fully charged, the electrolyte consist of 40% concentrated sulfuric acid and the remainder consist of mostly water. However, as it discharges, both the positive and the negative plates turn into lead sulfate with the electrolyte loosing much of its dissolved sulfuric acid and water.

7 0
4 years ago
Read 2 more answers
You just got a shipment of 10 network-attached laser printers. You want these printers to always have the same address but you w
love history [14]

Answer:

Configure Reservations

Explanation:

The reason you do this, is because you are getting a permanent IP address assignment.

Hope this helps!

6 0
3 years ago
Citations that are ______________________________ can be used to build a bibliography when needed. [Create and Modify Citation S
VMariaS [17]

Answer:

I think the best option would be C. Marked

Explanation:

hope this helps and sorry if it is incorrect.

8 0
3 years ago
The collection of all component frequencies iscalled _____________
yKpoI14uk [10]

Answer:

The answer is Frequency Spectrum.

Explanation:

The frequency spectrum is range of all component frequencies.It contains all the waves which are as following:-

Gamma Rays

X-Rays

Ultraviolet

Visible light.

Infrared

Micro wave

Radio wave

These all waves have their range of frequencies.The waves that are visible to us is only the visible light.

4 0
3 years ago
Other questions:
  • . When you create a template class, ___________.
    15·1 answer
  • Într-o curte sunt G găini și O oi. Să se determine numărul de capete și numărul de picioare din curte.
    13·1 answer
  • The Internet may best be compared to a/an
    8·1 answer
  • : Each individual data items of record is called a
    7·1 answer
  • One of the most common uses of spreadsheet programs are communicating with others. O editing images and photos. O tracking and m
    8·2 answers
  • Mark works as a Network Administrator for NetTech Inc. The company has a Windows Server 2008 domain-based network. The network c
    7·1 answer
  • What are the programming concepts (within or outside the scope of IT210) that you would like to strengthen and delve into furthe
    11·1 answer
  • Therapeutic services pays less than most other careers.<br><br><br> 1) True<br> 2) False
    12·2 answers
  • Do you know how to change your grades on a printer???????????
    13·1 answer
  • Where can a client identify the instant deposit options for their QuickBooks Payments account?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!