1 2 3 4 5 6 7 8 9 10 11 | class MyChoices: def __init__(self, **entries): self.__dict__.update(entries) self.choices = [ ] for val in entries.values(): for key in entries.keys(): if entries[key] == val: self.choices.append((val, key)) def get_choices(self): return self.choices |
Comments
Here is a similar solution which allows you to pass dictionaries to the constructor, and inserts the key/value pairs into the choice-list in the same manner they are in the dictionaries.
#