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
Identify a true statement to determine the number of columns in a web table.
Rainbow [258]
B (each column gets a caption)
7 0
3 years ago
Create a program that prompts the user for a positive integer then prints a right-aligned pyramid using that number using the st
Makovka662 [10]

Below is the program that prompts the user for a positive integer then prints a right-aligned pyramid in python programming language.

rows = int(input("Enter number of rows: "))  

for i1 in range(1, rows):  

   for j1 in range(1, i1 + 1):  

       # This prints multiplication / row-column  

       print(i1 * j1, end='  ')  

   print()  

What is Python in programming?

Python is a interpreted, high-level programming, object-oriented, language with a dynamic semantics. Its high-level built-in data structures, combined with dynamic typing and dynamic binding, make it very appealing for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together.

Python's simple, easy-to-learn syntax emphasizes readability, lowering the cost of program maintenance. Python also supports modules as well as packages, which promotes program's modularity and reuse of code. The Python interpreter and extensive standard library are freely distributable and available in source or binary form for all major platforms.

To learn more about Python, visit: brainly.com/question/28379867

#SPJ1

3 0
2 years ago
When using Microsoft word, what would happen to the text of a paragraph if the "Justify" option is used?
Bond [772]
Hello, and thank you for asking your question!

When you click on the 'Justify' option on any type of word pad, it'll make all lines of words perfectly aligned. Here is a quick few-sentence example I made. 
(Photo)

Hope this helps! ☺♥

3 0
3 years ago
Why we need each section of prologprogram?
evablogger [386]

Answer:

Prolog program are used in the artificial intelligence and the web development in a systematic manner process. As, it is also sometimes known as declarative language which basically consist of some facts and list. Prolog program are divided into the sections that are:

  • Domain sections
  • Clauses sections
  • Predicates sections
  • Goal sections

We need each section of the prolog program because all the sections introduced the systematic program and performed there particular functions so by using all these processing steps an efficient function are formed.

6 0
3 years ago
NEED HELP ASAP! Which field best organizes street addresses in a database?
pickupchik [31]

Answer:

name

Explanation:

5 0
3 years ago
Read 2 more answers
Other questions:
  • Query: [mcdonalds Austin] Viewport: Fresh User Location: within Houston, TX Result Returned: McDonalds location in a neighboring
    7·1 answer
  • Why are video games interesting?
    5·1 answer
  • a solid state drive is a removable flash memory device that you insert and remove from a slot in a computer, mobile device, or c
    5·1 answer
  • Is anyone else recieving a notification from brainly near the search bar about a message and click it and there nothing there???
    8·1 answer
  • What order? (function templates) Define a generic function called CheckOrder() that checks if four items are in ascending, neith
    14·1 answer
  • 71 81 77 15 63 96 36 51 77 18 17
    14·1 answer
  • Do you think the current video game industry is likely to experience another “crash” (similar to the one in the 1980s) any time
    10·1 answer
  • Select the items below that are examples of things that could use the smart card technology.
    7·1 answer
  • Hardware failure, power outages, and DOS attacks will affect:
    8·1 answer
  • State 10 differences between video conferencing and teleconferencing​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!