Skip to content

Instantly share code, notes, and snippets.

@pybites
Created January 11, 2021 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pybites/c964c34e46c84f5e9c9e335b098b3aaa to your computer and use it in GitHub Desktop.
Save pybites/c964c34e46c84f5e9c9e335b098b3aaa to your computer and use it in GitHub Desktop.
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