python key in dict.keys() performance for large dictionaries

后端 未结 5 1040
执念已碎
执念已碎 2020-12-09 20:22

I was wondering if you guys might be able to give me some advice in regards to making the performance of my code much better.

I have a set of for loops which look to

5条回答
  •  暖寄归人
    2020-12-09 21:03

    Using collections.defaultdict, this can be simplified to

    d = collections.defaultdict(list)
    for value in value_list:
        d[value.key].append(value.val)
    

提交回复
热议问题