Created
January 11, 2021 14:21
-
-
Save pybites/c964c34e46c84f5e9c9e335b098b3aaa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from importlib import import_module | |
from keyword import kwlist | |
import builtins | |
from typing import Dict, List | |
scores = { | |
"builtin": 1, | |
"keyword": 2, | |
"module": 3, | |
} | |
def score_objects(objects: List[str], | |
scores: Dict[str, int] = scores) -> int: | |
total = 0 | |
for obj in objects: | |
obj = str(obj) | |
if obj in dir(builtins): | |
total += scores['builtin'] | |
if obj in kwlist: | |
total += scores['keyword'] | |
try: | |
import_module(obj) | |
total += scores['module'] | |
except ModuleNotFoundError: | |
pass | |
return total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment