- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

When it is required to multiply adjacent elements, the 'zip' method, the 'tuple' method, and the generator expression can be used.

The zip method takes iterables, aggregates them into a tuple, and returns it as the result.

Generator is a simple way of creating iterators. It automatically implements a class with '__iter__()' and '__next__()' methods and keeps track of the internal states, as well as raises 'StopIteration' exception when no values are present that could be returned.

Below is a demonstration of the same −

my_tuple_1 = (7, 8, 0 ,3, 45, 3, 2, 22) print ("The tuple is : " ) print(my_tuple_1) my_result = tuple(i * j for i, j in zip(my_tuple_1, my_tuple_1[1:])) print("The tuple after multiplication is : ") print(my_result)

The tuple is : (7, 8, 0, 3, 45, 3, 2, 22) The tuple after multiplication is : (56, 0, 0, 135, 135, 6, 44)

- A tuple is defined, and is displayed on the console.
- It is zipped, along with the same tuple by leaving out the first element, and is iterated over, and the corresponding elements in the tuple are multipled.
- This result is assigned to a value.
- It is displayed as output on the console.

- Related Questions & Answers
- Python – Adjacent elements in List
- JavaScript: Adjacent Elements Product Algorithm
- Maximum decreasing adjacent elements in JavaScript
- Calculate difference between adjacent elements in given list using Python
- Program to find minimum possible difference of indices of adjacent elements in Python
- How to multiply two matrices by elements in R?
- Maximum sum of difference of adjacent elements in C++
- Finding element greater than its adjacent elements in JavaScript
- Maximum product of any two adjacent elements in JavaScript
- Program to find sum of non-adjacent elements in a circular list in python
- Program to find largest sum of non-adjacent elements of a list in Python
- Maximum product of 4 adjacent elements in matrix in C++
- Python - Joining only adjacent words in list
- Python program to multiply two matrices
- Ways to multiply n elements with an associative operation in C++

Advertisements