Hacker News new | past | comments | ask | show | jobs | submit login

I know that this is not a golf match, nevertheless, with the OP "this is what I would write in Python in real life" (eliding the module import) being:

  counts = collections.Counter()
  for line in sys.stdin:
    words = line.lower().split()
    counts.update(words)

  for word, count in counts.most_common():
    print(word, count)

I can't but resist to say what I would write in raku in "real life" (all in standard lib btw)...

  sub MAIN($in) {
    say $in.words>>.lc.Bag.sort(-*.value);
  }

This is Unicode safe and (imho) gives a good reflection that (i) raku is very good for whipping up string oriented 'one-liners' in functional stylee, (ii) that built in Set datatypes such as Bag are quite handy and (iii) that often a one-liner is better for expressing the coders' intent than a prosaic multi-line 'soup'.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: