title: Plural String Formatting
body: <p>Given a dictionary of <code>int</code>s, I'm trying to format a string with each number, and a pluralization of the item.</p>
  
  <p>Sample input <code>dict</code>:</p>
  
  <pre><code>data = {'tree': 1, 'bush': 2, 'flower': 3, 'cactus': 0}
  </code></pre>
  
  <p>Sample output <code>str</code>:</p>
  
  <pre><code>'My garden has 1 tree, 2 bushes, 3 flowers, and 0 cacti'
  </code></pre>
  
  <p>It needs to work with an arbitrary format string.</p>
  
  <p>The best solution I've come up with is a <code>PluralItem</code> class to store two attributes, <code>n</code> (the original value), and <code>s</code> (the string <code>'s'</code> if plural, empty string <code>''</code> if not). Subclassed for different pluralization methods</p>
  
  <pre><code>class PluralItem(object):
      def __init__(self, num):
          self.n = num
          self._get_s()
      def _get_s(self):
          self.s = '' if self.n == 1 else 's'
  
  class PluralES(PluralItem):
      def _get_s(self):
          self.s = 's' if self.n == 1 else 'es'
  
  class PluralI(PluralItem):
      def _get_s(self):
          self.s = 'us' if self.n == 1 else 'i'
  </code></pre>
  
  <p>Then make a new <code>dict</code> through comprehension and a <code>classes</code> mapping:</p>
  
  <pre><code>classes = {'bush': PluralES, 'cactus': PluralI, None: PluralItem}
  plural_data = {key: classes.get(key, classes[None])(value) for key, value in data.items()}
  </code></pre>
  
  <p>Lastly, the format string, and implementation:</p>
  
  <pre><code>formatter = 'My garden has {tree.n} tree{tree.s}, {bush.n} bush{bush.s}, {flower.n} flower{flower.s}, and {cactus.n} cact{cactus.s}'
  print(formatter.format(**plural_data))
  </code></pre>
  
  <p>Outputs the following:</p>
  
  <pre><code>My garden has 1 tree, 2 bushes, 3 flowers, and 0 cacti
  </code></pre>
  
  <hr>
  
  <p>For such an undoubtedly common need, I'm hesitant to throw in the towel with such a convoluted solution.</p>
  
  <p>Is there a way to format a string like this using the built-in <code>format</code> method, and minimal additional code? Pseudocode might be something like:</p>
  
  <pre><code>"{tree} tree{tree(s)}, {bush} bush{bush(es)}, {flower} flower{flower(s)}, {cactus} cact{cactus(i,us)}".format(data)
  </code></pre>
  
  <p>where parentheses return the contents if value is plural, or if contents has comma, means plural/singular</p>