Skip to content

Instantly share code, notes, and snippets.

@pybites
Created Jan 11, 2021
Embed
What would you like to do?
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