Question: Write a function list_comprehension() that takes input as a list A and generates a list of items B using a list comprehension in such a

Write a function list_comprehension() that takes input as a list A and generates a list of items B using a list comprehension in such a way that each item in B equals to a sum of two consecutive items in the original list A: B[i] = A[i] + A[i+1]. For example, if the original list is [1, 3, 2, 4] then the list comprehension should have the following items: [4, 5, 6] where 4 = 1 + 3, 5 = 3 + 2, 6 = 2 + 4. If the original list A has only one item, the comprehension list B should be empty. NOTE: Your function should contain only two lines of code: the header and the return statement!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!