Following are the Python program to sort the 2-dimensional array in descending order.
Program Explanation:
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