Skip to main content
Code Review

Return to Answer

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

As @mkrieger1 @mkrieger1 commented, you could use dict.get.

From the python docs:

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 a KeyError.

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.

From the python docs:

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 a KeyError.

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.

From the python docs:

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 a KeyError.

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.

deleted 66 characters in body
Source Link
Graipher
  • 41.6k
  • 7
  • 70
  • 134

As @mkrieger1 commented, you could use dict.get :dict.get.

From the python docs:

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 a KeyError.

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.

From the python docs:

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 a KeyError.

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.

From the python docs:

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 a KeyError.

As @mkrieger1 commented, you could use dict.get.

From the python docs:

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 a KeyError.

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.

Source Link
Graipher
  • 41.6k
  • 7
  • 70
  • 134

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.

From the python docs:

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 a KeyError.

lang-py

AltStyle によって変換されたページ (->オリジナル) /