Help handling python list

Hi everyone, i’m working on a 3d person game template and i’m having problem with my lock-on system

targets = []
targets1 = []
#GET A LIST OF ALL THE ENEMIES AND SORT THE BY DISTANCE TO THE PLAYER
for obj in scene.objects:
___if “ENEMY” in obj and obj not in targets:
___targets.append(obj)
___targets.sort(key=player.getDistanceTo)

         #GET A LIST OF ENEMIES I CAN LOCK_ON 
for obj in targets:

___if obj[‘ENEMY’] == 1 and obj not in targets1:
___targets1.append(obj)

I’m using the code in module mode with an always sensor on true pulse mode, the problem is that the list is constantly rewritten, preventing me from locking on a single target as i move accros the map.
How can i stop rewriting the list once i locked on an enemy?

sorry but the code wrapper didn’t work, turned the code blank