【发布时间】:2017-07-26 13:23:37
【问题描述】:
谁能简化这段代码背后的逻辑:
scores=[(similarity(prefs,person,other),other)
for other in prefs if other!=person ]
我尝试这样实现它
for others in prefs:
if others!=person:
scores=[similarity(prefs,person, others),others]
但它只选择其他元素的最后一个元素。 顺便说一句,prefs 是一个 2D 字典,而 score 应该是一个元组列表。
【问题讨论】:
标签: python python-2.7 logic list-comprehension