【发布时间】:2015-01-23 00:25:27
【问题描述】:
我在 Project Euler 上做 Problem 8,接下来我要做的是创建一个 dict,其中键为 1 - 1000,值是数字中的每个 int。
我尝试了各种方法,包括尝试使用 1-1001 的范围来创建键和嵌套 for 循环迭代数字,然后尝试 intDict[k] = j 其中 k 是范围循环中的数字,j 是来自数字循环,但似乎无法正确处理。 如何实现? 谢谢。
到目前为止我的代码:
def lrgProdOf5Numbers():
intDict = {}
highest = 0
f= open("1000dig.txt","r")
d = f.read()
f.close()
digits = [int(e) for e in str(d) ] #convert each number in string to int
【问题讨论】:
标签: python python-2.7 dictionary