How do I make a defaultdict safe for unexpecting clients?

后端 未结 5 2133
情话喂你
情话喂你 2021-01-05 15:00

Several times (even several in a row) I\'ve been bitten by the defaultdict bug: forgetting that something is actually a defaultdict and treating it like a regular dictionary

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-05 15:26

    You may still convert it to an normal dict.

    d = collections.defaultdict(list)
    d = dict(d)
    

提交回复
热议问题