O'Reilly logo

Exercises in Programming Style by Cristina Videira Lopes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7

Infinite Mirror

image

7.1 Constraints

  • All, or a significant part, of the problem is modeled using induction. That is, specify the base case (n0) and then the n + 1 rule.

7.2 A Program in this Style

  1 #!/usr/bin/env python
  2 import re, sys, operator
  3
  4 # Mileage may vary. If this crashes, make it lower
  5 RECURSION_LIMIT = 9500
  6 # We add a few more, because, contrary to the name,
  7 # this doesn't just rule recursion: it rules the
  8 # depth of the call stack
  9 sys.setrecursionlimit(RECURSION_LIMIT+10)
 10
 11 def count(word_list, stopwords, wordfreqs):
 12 # What to do with an empty list
 13 if word_list == []:
 14    return
 15 # The inductive ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required