items = ['abc', 'apple', 'pen', 'abc', 'pen', 'pc']
cache = {}
[cache.setdefault(item, len(cache)) for item in items]
from functools import lru_cache
from itertools import count
@lru_cache(maxsize=None)
def enumerate_as_seen(_, counter=count()):
return next(counter)
list(map(enumerate_as_seen, items))
lt= ['abc', 'apple', 'pen', 'abc', 'pen', 'pc']
lt_num=[sorted(list(set(lt))).index(x) for x in lt]
[0, 1, 3, 0, 3, 2]
>>> l = ['abc', 'apple', 'pen', 'abc', 'pen', 'pc']
>>> index_els = {v: k for k, v in reversed(tuple(enumerate(l)))}
>>> result = [index_els[k] for k in l]
>>> result
[0, 1, 2, 0, 2, 5]