One-liner to calculate the score based on two dicts
2
I have the following table of values:
scores = {
"proxy": 300,
"vpn": 500,
"tor": 900,
"recent_abuse": 1000,
}
And this data with booleans
data = {
"proxy": False,
"vpn": True,
"tor": False,
"recent_abuse": False,
}
What I want is to know if it possible to calculate in a single line (probably using itertools) a score based on data
My current code is this:
if data["proxy"]:
score += 300
if data["vpn"]:
score += 500
if data["tor"]:
score += 900
if data["recent_abuse"]:
score += 1000
python
-
sum([scores[key] for key in scores if data[key]]) – lllrnr101 Apr 8 at 15:09
Add a comment
|