defconstruct_large_dict(length=25000000, size=3): d = {} for i in tqdm(range(length)): l = [] for _ inrange(size): l.append(random.randint(0, 100)) d[i] = l return d
if __name__ == "__main__": d = construct_large_dict()
total = 0 start = time.time() for key in d: total += sum(d[key]) end1 = time.time() print("method-1 time: {}".format(end1 - start))
total = 0 for k, v in d.items(): total += sum(v) end2 = time.time() print("method-2 time: {}".format(end2 - end1))
total = 0 for k, v in d.iteritems(): total += sum(v) end3 = time.time() print("method-3 time: {}".format(end3 - end2))