I want to join multiple sets that are obtained from instances of a class. Below is an example of what I am working with and what I tried. Changing the class is not an option.
class Salad:
def __init__(self, dressing, veggies, others):
self.dressing = dressing
self.veggies = veggies
self.others = others
SALADS = {
'cesar' : Salad('cesar', {'lettuce', 'tomato'}, {'chicken', 'cheese'}),
'taco' : Salad('salsa', {'lettuce'}, {'cheese', 'chili', 'nachos'})
}
I want OTHER_INGREDIENTS to be {'chicken', 'cheese', 'chili', 'nachos'}. So I tried:
OTHER_INGREDIENTS = sum((salad.others for salad in SALADS.values()), set())
That gives me an error "unsupported operand type(s) for +: 'set' and 'set' though. How do I do this?
I would prefer to use Python 2.7 without additional imports if possible.