DECROMAX

COUNT CHARACTER FREQUENCY

Nov 9th, 2021
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | None | 0 0
  1. inp_string = 'Nobody expects the spanish inquisition'
  2. inp_string = inp_string.lower()
  3.  
  4. hold_dict = {}
  5. unique = [i for i in set([x for x in inp_string]) if i != ' ']
  6. for i in unique:
  7.     hold_dict[i] = inp_string.count(i)
  8.  
  9. sorted_dict = dict(sorted(hold_dict.items(), key=lambda x: x[1], reverse=True))
  10. print(sorted_dict)
Advertisement
Add Comment
Please, Sign In to add comment