1

I have the following Python code (simplified for brevity):

architecture = 'windows'

arch_windows = 125
arch_linux = 999

if architecture == 'windows':
    variable = arch_windows
else:
    variable = arch_linux

How can this assignment be simplified? In essence I'd like to be able to write it as: variable = value of variable with the name of ('arch_' + architecture)

because in my code I have a lot of such variables that I'd like to assign according to the value of a control variable (called architecture in the snippet)

Is it possible in Python?

rincEwind
  • 183
  • 1
  • 2
  • 7
  • 5
    Just create a dictionary: `arch = {"windows": 125, "linux": 999}`, then `arch[architecture]` to get the value. This is an exact use case for dictionaries. – Carcigenicate Aug 21 '21 at 18:37

0 Answers0