code: def choose(formatter, value, name, option, format):
      
      if not option:
          return
      words = format.split('|')
      num_words = len(words)
      if num_words < 2:
          return
      choices = option.split('|')
      num_choices = len(choices)
      # If the words has 1 more item than the choices, the last word will be
      # used as a default choice.
      if num_words not in (num_choices, num_choices + 1):
          n = num_choices
          raise ValueError('specify %d or %d choices' % (n, n + 1))
      choice = get_choice(value)
      try:
          index = choices.index(choice)
      except ValueError:
          if num_words == num_choices:
              raise ValueError('no default choice supplied')
          index = -1
      return formatter.format(words[index], value)
docs: Adds simple logic to format strings.
  
      Spec: `{:c[hoose](choice1|choice2|...):word1|word2|...[|default]}`
  
      Example::
  
         >>> smart.format(u'{num:choose(1|2|3):one|two|three|other}, num=1)
         u'one'
         >>> smart.format(u'{num:choose(1|2|3):one|two|three|other}, num=4)
         u'other'