forked from arsho/Hackerrank_Python_Domain_Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMostCommon.py
More file actions
21 lines (21 loc) · 717 Bytes
/
MostCommon.py
File metadata and controls
21 lines (21 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
'''
Title : Most Common
Subdomain : Collections
Domain : Python
Author : Ahmedur Rahman Shovon
Created : 15 July 2016
Problem : https://www.hackerrank.com/challenges/most-commons/problem
'''
import collections
s = sorted(input().strip())
s_counter = collections.Counter(s).most_common()
'''
s_counter_length = len(s_counter)
for i in range(0,s_counter_length,1):
for j in range(i+1,s_counter_length,1):
if (s_counter[i][1] == s_counter[j][1]) and (ord(s_counter[j][0]) < ord(s_counter[i][0])):
s_counter[i],s_counter[j] = s_counter[j],s_counter[i]
'''
s_counter = sorted(s_counter,key = lambda x: (x[1] * -1,x[0]))
for i in range(0,3):
print(s_counter[i][0],s_counter[i][1])