fork download
  1. import re
  2.  
  3. def checkio(text):
  4. text = re.sub('[^a-z]', '', text.lower())
  5.  
  6. alph = {}
  7. for char in text:
  8. if char not in alph.keys():
  9. alph[char] = text.count(char)
  10.  
  11. return sorted(alph.items(), key=lambda x: (-x[1], x[0]))
  12.  
  13. if __name__ == '__main__':
  14. print( checkio("Hellooaaaacccc bbbbWorld!") )
  15.  
Success #stdin #stdout 0.1s 10088KB
stdin
Standard input is empty
stdout
[('a', 4), ('b', 4), ('c', 4), ('l', 3), ('o', 3), ('d', 1), ('e', 1), ('h', 1), ('r', 1), ('w', 1)]