====== 8th programming lab ====== Spam continued * [[courses:ae4b99rph:labs:spam:step5]] * [[courses:ae4b99rph:labs:spam:step6]] ===== live programming session ===== * reading from a text file, revisited * what it happens when a module is imported, ... * if __name__ == '__main__': * iterable vs generator ===== word counter ===== How to implement a word counter - function ''compute_word_frequencies'' Imagine a text file ''example.txt'' that contains: one one two one two three one two three four >>> from texttools import compute_word_frequencies >>> compute_word_frequencies('example.txt') {'one': 4, 'two': 3, 'three': 2, 'four': 1}