As @mkrieger1 @mkrieger1 commented, you could use dict.get
.
get(key[, default])
Return the value for key if key is in the dictionary, else default. If default is not given, it defaults to
None
, so that this method never raises aKeyError
.
REDUCE_VALUE = {
"honda": 0.95,
"suzuki": 0.85,
}
>>> REDUCE_VALUE.get('suzuki', 0.95)
0.85
>> REDUCE_VALUE.get('yamaha', 0.95)
0.95
Normally, you would probably define the default value as a constant, instead of having it as a magic number as I did here.
As @mkrieger1 commented, you could use dict.get
.
get(key[, default])
Return the value for key if key is in the dictionary, else default. If default is not given, it defaults to
None
, so that this method never raises aKeyError
.
REDUCE_VALUE = {
"honda": 0.95,
"suzuki": 0.85,
}
>>> REDUCE_VALUE.get('suzuki', 0.95)
0.85
>> REDUCE_VALUE.get('yamaha', 0.95)
0.95
Normally, you would probably define the default value as a constant, instead of having it as a magic number as I did here.
As @mkrieger1 commented, you could use dict.get
.
get(key[, default])
Return the value for key if key is in the dictionary, else default. If default is not given, it defaults to
None
, so that this method never raises aKeyError
.
REDUCE_VALUE = {
"honda": 0.95,
"suzuki": 0.85,
}
>>> REDUCE_VALUE.get('suzuki', 0.95)
0.85
>> REDUCE_VALUE.get('yamaha', 0.95)
0.95
Normally, you would probably define the default value as a constant, instead of having it as a magic number as I did here.
As @mkrieger1 commented, you could use dict.get
:dict.get
.
get(key[, default])
Return the value for key if key is in the dictionary, else default. If default is not given, it defaults to
None
, so that this method never raises aKeyError
.
REDUCE_VALUE = {
"honda": 0.95,
"suzuki": 0.85,
}
>>> REDUCE_VALUE.get('suzuki', 0.95)
0.85
>> REDUCE_VALUE.get('yamaha', 0.95)
0.95
Normally, you would probably define the default value as a constant, instead of having it as a magic number as I did here.
get(key[, default])
Return the value for key if key is in the dictionary, else default. If default is not given, it defaults to
None
, so that this method never raises aKeyError
.
As @mkrieger1 commented, you could use dict.get
:
REDUCE_VALUE = {
"honda": 0.95,
"suzuki": 0.85,
}
>>> REDUCE_VALUE.get('suzuki', 0.95)
0.85
>> REDUCE_VALUE.get('yamaha', 0.95)
0.95
Normally, you would probably define the default value as a constant, instead of having it as a magic number as I did here.
get(key[, default])
Return the value for key if key is in the dictionary, else default. If default is not given, it defaults to
None
, so that this method never raises aKeyError
.
As @mkrieger1 commented, you could use dict.get
.
get(key[, default])
Return the value for key if key is in the dictionary, else default. If default is not given, it defaults to
None
, so that this method never raises aKeyError
.
REDUCE_VALUE = {
"honda": 0.95,
"suzuki": 0.85,
}
>>> REDUCE_VALUE.get('suzuki', 0.95)
0.85
>> REDUCE_VALUE.get('yamaha', 0.95)
0.95
Normally, you would probably define the default value as a constant, instead of having it as a magic number as I did here.
As @mkrieger1 commented, you could use dict.get
:
REDUCE_VALUE = {
"honda": 0.95,
"suzuki": 0.85,
}
>>> REDUCE_VALUE.get('suzuki', 0.95)
0.85
>> REDUCE_VALUE.get('yamaha', 0.95)
0.95
Normally, you would probably define the default value as a constant, instead of having it as a magic number as I did here.
get(key[, default])
Return the value for key if key is in the dictionary, else default. If default is not given, it defaults to
None
, so that this method never raises aKeyError
.