>>> nums1 = [3, 1, 4] >>> nums2 = [2, 7, 1] >>> [ sum(i) for i in zip(nums1, nums2)] [5, 8, 5]
On Wed, Apr 23, 2014 at 1:12 PM, Danny Yoo <d...@hashcollision.org> wrote: > Hi Sunil, > > > Try a simpler but related problem first. > > Say that you have two lists of numbers, like: > > ###### > nums1 = [3, 1, 4] > nums2 = [2, 7, 1] > ###### > > Can you design a function addLists() that takes two lists of numbers > of equal length, and adds them together? For example, > > addLists(nums1, nums2) == [5, 8, 5] > > should be true, as well as: > > addLists([4, 6], [8, 5]) == [12, 11] > > > Would you be able to write the addLists() function? Would you be able > to write a few test cases to check that the implementation works on > those examples? > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor