You can use a map dictionary:
d = {'apple':1, 'bat':2, 'car':3, 'pet':4}
L = ['apple','bat','apple','car','pet','bat']
[d[x] for x in L] # [1, 2, 1, 3, 4, 2]
For auto creating map dictionary you can use defaultdict(int)
with a counter.
from collections import defaultdict
d = defaultdict(int)
co = 1
for x in L:
if not d[x]:
d[x] = co
co+=1
d # defaultdict(, {'pet': 4, 'bat': 2, 'apple': 1, 'car': 3})
Or as @Stuart mentioned you can use d = dict(zip(set(L), range(len(L))))
for creating dictionary