Create dictionary for choice list
763680
def _setChoiceDict(self):
        """"""
        # value is name of choice parameter (same as key)
        self.choiceDict = {}
        for c in self.choice: self.choiceDict[c] = c
1208953
def options(cls):
        """"""
        return {k: v for k, v in cls.__dict__.items() if isinstance(v, Option)}
1369216
def build(c: Union[Text, 'Choice', Dict[Text, Any]]) -> 'Choice':
        """"""

        if isinstance(c, Choice):
            return c
        elif isinstance(c, str):
            return Choice(c, c)
        else:
            return Choice(c.get('name'),
                          c.get('value'),
                          c.get('disabled', None),
                          c.get('checked'),
                          c.get('key'))
1232165
def _get_choices(self):
        
        if not self._choices:
            self._choices = tuple(
                (x.name, getattr(x, 'verbose_name', x.name) or x.name)
                for x in self.choices_class.constants()
            )
        return self._choices
124991
def weighted_choice(choices):
    
    values, weights = zip(*choices)
    total = 0
    cum_weights = []
    for w in weights:
        total += w
        cum_weights.append(total)
    x = random.uniform(0, total)
    i = bisect.bisect(cum_weights, x)
    return values[i]
1229495
def get_select_items(items):
    """"""
    option_items = list()
    for item in items:
        if isinstance(item, dict) and defs.VALUE in item and defs.LABEL in item:
            option_items.append(item[defs.VALUE])
        else:
            raise exceptions.ParametersFieldError(item, "a dictionary with {} and {}"
                                                  .format(defs.LABEL, defs.VALUE))
    return option_items
943334
def multiple_choice(name, choices = [], options = {})
      field name, MultipleChoiceField.new(choices, options)
    end
849312
def choices(self):
        """"""
        if self._choices:
            return self._choices
        for n in os.listdir(self._voicedir):
            if len(n) == 1 and os.path.isdir(os.path.join(self._voicedir, n)):
                self._choices.append(n)
        return self._choices
1326508
def get_choices(cls, category):
        """"""
        value = cls._DEFAULTS[category]
        if not isinstance(value, list):
            raise ValueError("{} does not offer choices".format(category))
        return value
1232204
def convert_option_dict_to_dict(option_dict):
    """"""
    ret_dict = {}
    for key, value in option_dict.items():
        if is_null(value):
            ret_dict[key] = None
        elif isinstance(value, tuple):
            ret_dict[key] = value[0]
        else:
            ret_dict[key] = value
    return ret_dict
913312
def comma_choice_list(cls, string):
        ''''''
        items = string.split(',')
        items = CommaChoiceListArgs([item.strip() for item in items])
        return items
436048
def get_choice(prompt, choices):
    
    print()
    checker = []
    for offset, choice in enumerate(choices):
        number = offset + 1
        print("\t{}): '{}'\n".format(number, choice))
        checker.append(str(number))

    response = get_input(prompt, tuple(checker) + ('',))
    if not response:
        print("Exiting...")
        exit()

    offset = int(response) - 1
    selected = choices[offset]

    return selected
117467
def dict_pick(dictionary, allowed_keys):
    
    return {key: value for key, value in viewitems(dictionary) if key in allowed_keys}
562733
def _default_dict(self):
        """"""
        options = {}
        for attr, _, _, default, multi, _ in self._optiondict.values():
            if multi and default is None:
                options[attr] = []
            else:
                options[attr] = default
        return options
945337
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'consumption_preference_category_id'
                  ) and self.consumption_preference_category_id is not None:
            _dict[
                'consumption_preference_category_id'] = self.consumption_preference_category_id
        if hasattr(self, 'name') and self.name is not None:
            _dict['name'] = self.name
        if hasattr(self, 'consumption_preferences'
                  ) and self.consumption_preferences is not None:
            _dict['consumption_preferences'] = [
                x._to_dict() for x in self.consumption_preferences
            ]
        return _dict
1043571
def get_user_choice(items):
    '''
    '''
    choice = raw_input('Choose an item or "q" to quit: ')
    while choice != 'q':
        try:
            item = items[int(choice)]
            print  # Blank line for readability between interactive views
            return item
        except ValueError:
            # Passed something that cound't be converted with int()
            choice = raw_input('You entered a non-integer. Choice must be an'
                               ' integer or "q": ')
        except IndexError:
            # Passed an integer that was out of range of the list of urls
            choice = raw_input('You entered an invalid integer. Choice must be'
                               ' from above url list or "q": ')
    return None
211973
def _convert_choices(self, choices):
        """"""

        final_choices = []
        for choice in choices:

            if isinstance(choice, ChoiceEntry):
                final_choices.append(choice)
                continue

            original_choice = choice
            if isinstance(choice, six.string_types):
                if choice == _NO_SUBSET_NAME_:
                    continue
                choice = [choice, ]
            else:
                choice = list(choice)

            length = len(choice)

            assert 1 <= length <= 4, 'Invalid number of entries in %s' % (original_choice,)

            final_choice = []

            # do we have attributes?
            if length > 1 and isinstance(choice[-1], Mapping):
                final_choice.append(choice.pop())
            elif length == 4:
                attributes = choice.pop()
                assert attributes is None or isinstance(attributes, Mapping), 'Last argument must be a dict-like object in %s' % (original_choice,)
                if attributes:
                    final_choice.append(attributes)

            # the constant
            final_choice.insert(0, choice.pop(0))

            if len(choice):
                # we were given a db value
                final_choice.insert(1, choice.pop(0))
                if len(choice):
                    # we were given a display value
                    final_choice.insert(2, choice.pop(0))
            else:
                # set None to compute it later
                final_choice.insert(1, None)

            if final_choice[1] is None:
                # no db value, we compute it from the constant
                final_choice[1] = self.value_transform(final_choice[0])

            final_choices.append(final_choice)

        return super(AutoChoices, self)._convert_choices(final_choices)