Created
January 11, 2021 14:21
-
-
Save pybites/c964c34e46c84f5e9c9e335b098b3aaa to your computer and use it in GitHub Desktop.
Revisions
-
pybites created this gist
Jan 11, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ 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