Answers for "how to place an id to every element in list in python"

0

how to place an id to every element in list in python

from collections import defaultdict

omg = ['a', 'b', 'c', 'a', 'b', 1]
d = defaultdict(lambda: len(d))  # late binding allows d not to be defined yet
omg_id = [d[x] for x in omg]
# [0, 1, 2, 0, 1, 3]
Posted by: Guest on December-03-2020

Code answers related to "how to place an id to every element in list in python"

Python Answers by Framework

Browse Popular Code Answers by Language