且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python从项目列表创建字典键

更新时间:2023-02-17 12:54:44

使用元组代替列表。元组是不可变的,可以用作字典键:

Use a tuple in place of the list. Tuples are immutable and can be used as dictionary keys:

d[(attrib_a, attrib_b)] = t

括号可以省略:

d[attrib_a, attrib_b] = t

然而,有些人似乎不喜欢这种语法。

However, some people seem to dislike this syntax.