Skip to content

Commit 1007416

Browse files
committed
OrderedDict 插入顺序
1 parent 8fc6d7d commit 1007416

File tree

1 file changed

+1
-1
lines changed
  • docs/19_python内置常用算法和数据结构

1 file changed

+1
-1
lines changed

docs/19_python内置常用算法和数据结构/builtins.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ maxk, maxv = maximum, mydict[maximum]
147147
# 或者
148148
maxk, maxv = max(mydict.items(), key=lambda k: k[1])
149149

150-
# 支持默认值的有序字典 (OrderedDict and defaultdict)
150+
# 支持默认值的有序字典 (OrderedDict and defaultdict) (注意是 key 插入顺序不是字典序)
151151
# https://stackoverflow.com/questions/6190331/how-to-implement-an-ordered-default-dict
152152
od = OrderedDict() # collections.OrderedDict()
153153
od[i] = od.get(i, 0) + 1 # 间接实现了 defaultdict(int) ,同时保持了插入字典的 key 顺序

0 commit comments

Comments
 (0)