Let's say I have a variable called temperature. And I want its value to be different according to the conditions. Normally I would do something like this:
temperature = None country = input() if country == 'USA' : temperature = 10 elif country == 'Spain': temperature = 20 elif country == 'Peru': temperature = 30 #and so on
But that takes forever, if I have many values. I have a feeling I need to use sets but I haven't begun using them (and dictionaries). However if that is the way to do it, I'd like to know.
Do you mean something like that?
country = input() cond = {'USA': 10, 'Spain': 20, 'Peru': 30 } temperature = cond.get( country, None )
2.1m questions
2.1m answers
60 comments
57.0k users