python RuntimeError: dictionary changed size during iteration

前端 未结 5 1960
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 12:32

I have obj like this

{hello: \'world\', \"foo.0.bar\": v1, \"foo.0.name\": v2, \"foo.1.bar\": v3}

It should be expand to

{         


        
5条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 13:15

    You might want to copy your keys in a list and iterate over your dict using the latter, eg:

    def expand(obj):
        keys = obj.keys()
        for k in keys:
            expandField(obj, k, v)
    

    I let you analyse if the resulting behavior suits your expected results.

提交回复
热议问题