Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PLT-02 How to Count Words

kanaya
April 27, 2024
24

PLT-02 How to Count Words

kanaya

April 27, 2024
Tweet

Transcript

  1. pineapple.cc ߏ଄Խఆཧ Structured Program Theorem w ࿈઀ʢஞ࣮࣍ߦʣ w "#$ w

    બ୒ʢ৚݅෼ذʣ • If Condition_Is_Good Then Do_This Else Do_That w ܁ฦ͠ • While Condition_Is_Good Do Something • Repeat Something Until Condition_Is_Bad
  2. pineapple.cc import sys import re filename = sys.argv[1] fp =

    open(filename) data = fp.read() words = data.split() fp.close() word_freq = {} for raw_word in words: word = re.sub('[^A-Za-z]', '', raw_word).lower() if word not in word_freq: word_freq[word] = 0 word_freq[word] += 1 word_sorted = sorted(word_freq.items(), key=lambda x:x[1], reverse=True) for word in word_sorted: print("{} {}".format(word[1], word[0])) Python
  3. pineapple.cc cat the-great-gatsby.txt | tr '[A-Z]' '[a-z]' | tr -C

    '[a-z ]' -d | sed 's/ /\n/g' | sort | uniq -c | sort -nr
  4. pineapple.cc ݟͤࢉ Misezan w O👀O w O👀LLXIFSFOL w 👀 👀

    w 👀 👀 w 👀 👀 Math
  5. pineapple.cc ؔ਺ͱԋࢉࢠʢ࡞༻ૉʣ Functions and operators w ʴ w — w

    º w × w ˢ w 👀 w TVN    w EJ ff    w QSPE    w RVPU    w QPX    w HBO  
  6. pineapple.cc ؔ਺ద༻ͷॻ͖ํ Notation of applying function to parameters w Ұൠతͳॻ͖ํ

    w ZG Y  w VH W X  w ΧϦʔ෩ຯͷॻ͖ํ w ZGY w VHWX
  7. pineapple.cc ؔ਺ద༻ͷॻ͖ํ How to write functional application w ZG Y

     w [H Z XIFSFZG Y  w [H G Y  w [ HwG Y  w ZZY PSZY👉G  w [HZXIFSFZGY w [H GY  w [ HwG Y w [Y👉G💘H