Given an array sort it according to frequency of elements in descending order
Answers
Answered by
0
The Python Code is:
Method 1:
def Sorting(lst):
lst.sort(key=len)
return lst
lst = ["rohan", "amy", "sapna", "muhammad",
"aakash", "raunak", "chinmoy"]
Ist. reverse()
print(Sorting(lst))
Method 2:
import collections
def CountFrequency(arr):
return collections.Counter(arr)
if __name__ == "__main__":
arr = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 5, 5]
freq = CountFrequency(arr)
for key, value in freq.iteritems():
print(key, " -> ", value)
If you have Some more questions, then contact me at:
Email: [email protected]
Youtube: shorturl.at/mnB57
Similar questions