Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 Python 2.4 中是否有更好的方法来执行以下操作?
if id in id_dict: id_dict[id].append(skill) else: id_dict[id] = [skill]
如果id在字典中,则返回其值。如果不是,则插入id值[]并返回[]。
id
[]
id_dict.setdefault(id, []).append(skill)