Hacker News new | ask | show | jobs
by teddyh 1089 days ago
Python:

  >>> sentence = """Only the fool would take trouble to verify that his sentence was composed of ten a's, three b's, four c's, four d's, forty-six e's, sixteen f's, four g's, thirteen h's, fifteen i's, two k's, nine l's, four m's, twenty-five n's, twenty-four o's, five p's, sixteen r's, forty-one s's, thirty-seven t's, ten u's, eight v's, eight w's, four x's, eleven y's, twenty-seven commas, twenty-three apostrophes, seven hyphens and, last but not least, a single !"""
  >>> import collections
  >>> sorted(collections.Counter(sentence.lower()).items())
  [(' ', 73), ('!', 1), ("'", 23), (',', 27), ('-', 7), ('a', 10), ('b', 3), ('c', 4), ('d', 4), ('e', 46), ('f', 16), ('g', 4), ('h', 13), ('i', 15), ('k', 2), ('l', 9), ('m', 4), ('n', 25), ('o', 24), ('p', 5), ('r', 16), ('s', 41), ('t', 37), ('u', 10), ('v', 8), ('w', 8), ('x', 4), ('y', 11)]
Checks out.