我试图了解此代码如何以长格式列出
proposed = dict((k, v) for k, v in args.iteritems() if v is not None)
我能想出的最好的是以下内容,但它不起作用:
for k,v in args.iteritems():
print "value of v is: %s" % v
if v is not None:
proposed = dict(k,v)
但是它会引发以下错误:
TypeError:dict最多需要1个参数,得到2
答案 0 :(得分:2)
尝试:
proposed=dict()
for k,v in args.iteritems():
print "value of v is: %s" % v
if v is not None:
proposed[k] = v #This is the part you got wrong