默认列表转字典

from collections import defaultdict

# 将列表内的元素,根据位数合并成字典
lst = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 32769, 65536, 4294967296]

dic = defaultdict(list)
for i in lst:
    dic[len(str(i))].append(i)
print(dict(dic))

 

posted @ 2020-09-15 14:33  流年中渲染了微笑  阅读(114)  评论(0编辑  收藏  举报