【发布时间】:2011-04-26 09:34:14
【问题描述】:
Input: two lists (list1, list2) of equal length
Output: one list (result) of the same length, such that:
result[i] = list1[i] + list2[i]
有什么简洁的方法可以做到这一点吗?或者这是最好的:
# Python 3
assert len(list1) == len(list2)
result = [list1[i] + list2[i] for i in range(len(list1))]
【问题讨论】:
-
我最初将其读作“毫无意义的明智之和”。我想我可能需要睡觉了。