I have been maintaining a project. I found that someone wrote a function where he has made an import statement inside a for loop like so
for obj in obj_list:
from Levenshtein._levenshtein import distance
if distance(obj.title, "some string") <= 2:
do something
I assume that importing something inside a for loop causes unnecessary instruction execution. Hence, I want to refactor the code. But to do that I need a rationale to support my assumption that importing inside a for loop is not a good practice. Is my assumption correct?