我正在寻找从嵌套循环创建一个字典,该字典循环访问日期和变量。考虑到我的约会时间是〜400和myvars〜50,000,我想尽可能高效地创建它。非常感谢。
fmap = dict.fromkeys(range(len(dates)*len(myvars)))
count = 0
for j in dates:
for i in myvars:
fmap[count] = partial(dosomething, i, j)
count = count+1
答案 0 :(得分:1)
您可以执行此操作,它应该非常有效:
count = len(dates) * len(myvars)
fmap = dict(zip(range(count), [partial(dosomething, i, j) for j in dates for i in myvars]))