You are here: > Dive Into Python > Dynamic functions | << >> | ||||
Dive Into PythonPython from novice to pro |
I want to talk about plural nouns. Also, functions that return other functions, advanced regular expressions, and generators. Generators are new in Python 2.3. But first, let's talk about how to make plural nouns.
If you haven't read , now would be a good time. This chapter assumes you understand the basics of regular expressions, and quickly descends into more advanced uses.
English is a schizophrenic language that borrows from a lot of other languages, and the rules for making singular nouns into plural nouns are varied and complex. There are rules, and then there are exceptions to those rules, and then there are exceptions to the exceptions.
If you grew up in an English-speaking country or learned English in a formal school setting, you're probably familiar with the basic rules:
(I know, there are a lot of exceptions. Man becomes men and woman becomes women, but human becomes humans. Mouse becomes mice and louse becomes lice, but house becomes houses. Knife becomes knives and wife becomes wives, but lowlife becomes lowlifes. And don't even get me started on words that are their own plural, like sheep, deer, and haiku.)
Other languages are, of course, completely different.
Let's design a module that pluralizes nouns. Start with just English nouns, and just these four rules, but keep in mind that you'll inevitably need to add more rules, and you may eventually need to add more languages.
<< Summary | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | | plural.py, stage 1 >> |