Get reliable answers to your questions at Westonci.ca, where our knowledgeable community is always ready to help. Discover comprehensive answers to your questions from knowledgeable professionals on our user-friendly platform. Explore comprehensive solutions to your questions from a wide range of professionals on our user-friendly platform.
Sagot :
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
Thank you for choosing our service. We're dedicated to providing the best answers for all your questions. Visit us again. Thanks for using our platform. We aim to provide accurate and up-to-date answers to all your queries. Come back soon. We're glad you visited Westonci.ca. Return anytime for updated answers from our knowledgeable team.