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
Write a program that defines a type for a structure that stores information on a student in ENG EK 125. Declare two variables to
Mashcka [7]

Answer:

Following are the program in the C Programming Language.

#include<stdio.h> //header file

#include<string.h> //header file

struct student//creating structure

{

 //set integer variables

int marks;

int roll;

};

//define function

void initial(struct student *stu)

{

 //set integer type variables

int marks=420;

int roll_no=45,i;

stu->marks=marks;//assigning the values

stu->roll=roll_no;//assigning the values

}

//define main method to call the function

int main()

{

struct student stu;

initial(&stu);//calling the function

printf("Total marks : %d\n",stu.marks); //print output

printf("Roll No. : %d\n",stu.roll); //print output

return 0;

}

<u>Output:</u>

Total marks : 420

Roll No. : 45

Explanation:

Here, we define the structure "student" with a struct keyword for creating a structure.

  • inside the structure, we set two integer type variable "marks", "roll".

Then, we define a function "initial()" and pass an argument in the parameter of the function.

  • inside the function, we set two integer type variable "marks", "roll_no" and assign the value in the variable "marks" to 420 and variable "roll_no" to 45.
  • Assign the value in the structure's integer variables from the function's variable.

Finally, we set the main method inside it we call the function "initial()" and pass the value and then, we print the output with message.

8 0
4 years ago
What is one of the benefits of using a library in a program?
Phoenix [80]

Answer:

Simplifies creating a complex program

Explanation:

7 0
3 years ago
A smart card is?
Tom [10]

Answer:

i think....(b)

Explanation:

please say yes or no answer....

8 0
3 years ago
An administrator has been working within an organization for over 10 years. He has moved between different IT divisions within t
rodikova [14]

Answer:

User roles and access authorization

(Explanation of this question is given below in the explanation section.

Explanation:

As noted in question that a terminated employee comeback in office and installed some malicious script on a computer that was scheduled to run a logic bomb on the first day of the following month. And, that script will change administrator passwords, delete files, and shut down over 100 servers in the data center.

The following problem can be with that account

  • Unauthorized user access and privileges

The user may be given unauthorized access to system resources. If a user has unauthorized access to system resource then he can modify or destroy the system function easily.

  • The firewall may be disabled to detect the malicious script

The firewall should be enabled to detect such types of attack from unauthorized access to the system

  • Role

May be user role is not defined properly. If role would be defined according to user role then there are very fewer chances in doing unauthorized changes in the system that will result in an unexpected outage.

5 0
4 years ago
What is the speed limit in school zone
Mkey [24]
School zones typically have speed limits between 15 and 25 mph (25 and 40 km/h).
8 0
4 years ago
Read 2 more answers
Other questions:
  • Andy designed a web page for a product-oriented industry using CSS properties. He used several HTML tags to create the web page.
    6·1 answer
  • How can I print an int as a char in C?
    13·2 answers
  • Complete the function to replace any period by an exclamation point. Ex: "Hello. I'm Miley. Nice to meet you." becomes:
    9·1 answer
  • PLEASE HELP! Which aspect helps you to change the luminescence of your image?
    10·2 answers
  • When performing actions between your computer and one that is infected with a virus, which of the following offers NO risk of yo
    11·1 answer
  • Which of these items will least likely increase pressure in the evaporative emission control system?
    9·1 answer
  • 1. Before operating any power tool, you need to
    14·1 answer
  • Which are examples of ribbon customizations?
    11·1 answer
  • Question 1 (1 point)
    5·2 answers
  • What practice makes it virtually impossible to figure out the geographic location of a company?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!