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))