{"id":18202,"date":"2021-08-26T10:42:14","date_gmt":"2021-08-26T05:12:14","guid":{"rendered":"https:\/\/python-programs.com\/?p=18202"},"modified":"2021-11-22T18:37:14","modified_gmt":"2021-11-22T13:07:14","slug":"python-program-to-replace-every-list-element-by-multiplication-of-previous-and-next","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-replace-every-list-element-by-multiplication-of-previous-and-next\/","title":{"rendered":"Python Program to Replace Every List Element by Multiplication of Previous and Next"},"content":{"rendered":"

In the previous article, we have discussed Python Program for Double Factorial<\/a>
\nGiven a list and the task is to replace each element of a list by multiplying the previous and next elements.<\/p>\n

The first element is replaced by multiplying the first and second elements.<\/p>\n

The last element is replaced by multiplying the last and second last elements.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given list = [7, 8, 1, 2, 3, 4]<\/pre>\n

Output:<\/strong><\/p>\n

The given List after replacing each element of a list by multiplying the previous and next elements:\r\n56 7 16 3 8 12<\/pre>\n

Explanation:<\/strong><\/p>\n

Given List = [7*8, 7*1, 8*2, 1*3, 2*4, 3*4]<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given list =[ 10 ,1 ,20, 2 ,30, 3]<\/pre>\n

Output:<\/strong><\/p>\n

The given List after replacing each element of a list by multiplying the previous and next elements:\r\n10 200 2 600 6 90<\/pre>\n

Explanation:<\/strong><\/p>\n

Given List = [10*1, 10*20, 1*2, 20*30, 2*3, 30*3] = [10, 200, 2, 600, 6, 90]<\/pre>\n

Program to Replace Every List Element by Multiplication of Previous and Next in Python<\/h2>\n

Below are the ways to replace each element of a list by multiplying the previous and next elements.<\/p>\n