code: def to_choices_dict(choices):
      
      # Allow single, paired or grouped choices style:
      # choices = [1, 2, 3]
      # choices = [(1, 'First'), (2, 'Second'), (3, 'Third')]
      # choices = [('Category', ((1, 'First'), (2, 'Second'))), (3, 'Third')]
      ret = OrderedDict()
      for choice in choices:
          if (not isinstance(choice, (list, tuple))):
              # single choice
              ret[choice] = choice
          else:
              key, value = choice
              if isinstance(value, (list, tuple)):
                  # grouped choices (category, sub choices)
                  ret[key] = to_choices_dict(value)
              else:
                  # paired choice (key, display value)
                  ret[key] = value
      return ret
docs: Convert choices into key/value dicts.
  
      pairwise_choices([1]) -> {1: 1}
      pairwise_choices([(1, '1st'), (2, '2nd')]) -> {1: '1st', 2: '2nd'}
      pairwise_choices([('Group', ((1, '1st'), 2))]) -> {'Group': {1: '1st', 2: '2nd'}}