gpt4 book ai didi

python - 试图理解精简的 Python

转载 作者:太空宇宙 更新时间:2023-11-04 02:57:40 25 4
gpt4 key购买 nike

我试图理解这段代码如何以长格式布局

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 expected at most 1 arguments, got 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

关于python - 试图理解精简的 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41904597/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com