Warning
This page is located in archive.

8th programming lab

Spam continued

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}

courses/ae4b99rph/labs/weekly/week_08.txt · Last modified: 2013/11/13 19:35 by svobodat