I'm not sure if I'm using the correct terminology, but here's my code:
class Candidate(object):
def __init__(self, party_code, state, age=random.randint(35, 70),
social_index=(1 if party_code == 'dem' else -1 if party_code == 'rep' else 0),
econ_index=(-1 if party_code == 'dem' else 1 if party_code == 'rep' else 0)):
self.state = state
self.party_code = party_code
self.age = age
self.social_index = social_index
self.econ_index = econ_index
I would like to be able to use party_code to determine what the initial values of social_index and econ_index will be, but this isn't allowed with the way I currently have it set up. Is there an alternative way to dynamically set keyword variable on creation of this class?