[英]Trying to understand condensed Python
我試圖了解這段代碼是如何以長格式布局的
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)
但是它會引發以下錯誤:
類型錯誤:dict 預計最多 1 個參數,得到 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.