📌  相关文章
📜  如何在python代码示例中为列表中的每个元素放置一个id

📅  最后修改于: 2022-03-11 14:46:33.736000             🧑  作者: Mango

代码示例1
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]