Sometimes, while working with data, we can have a problem in which we need to find cumulative result. This can be of any type, product or summation. Here we are gonna discuss about adjacent element addition. Let’s discuss certain ways in which this task can be performed.

**Method #1 : Using zip() + generator expression + tuple()**

The combination of above functionalities can be used to perform this task. In this, we use generator expression to provide addition logic and simultaneous element pairing is done by zip(). The result is converted to tuple form using tuple().

`# Python3 code to demonstrate working of ` `# Pairwise Addition in Tuples ` `# using zip() + generator expression + tuple ` ` ` `# initialize tuple ` `test_tup ` `=` `(` `1` `, ` `5` `, ` `7` `, ` `8` `, ` `10` `) ` ` ` `# printing original tuple ` `print` `(` `"The original tuple : "` `+` `str` `(test_tup)) ` ` ` `# Pairwise Addition in Tuples ` `# using zip() + generator expression + tuple ` `res ` `=` `tuple` `(i ` `+` `j ` `for` `i, j ` `in` `zip` `(test_tup, test_tup[` `1` `:])) ` ` ` `# printing result ` `print` `(` `"Resultant tuple after addition : "` `+` `str` `(res)) ` |

*chevron_right*

*filter_none*

**Output :**

The original tuple : (1, 5, 7, 8, 10) Resultant tuple after addition : (6, 12, 15, 18)

**Method #2 : Using tuple() + map() + lambda**

The combination of above functions can also help to perform this task. In this, we perform addition and binding logic using lambda function. The map() is used to iterate to each element and at end result is converted by tuple().

`# Python3 code to demonstrate working of ` `# Pairwise Addition in Tuples ` `# using tuple() + map() + lambda ` ` ` `# initialize tuple ` `test_tup ` `=` `(` `1` `, ` `5` `, ` `7` `, ` `8` `, ` `10` `) ` ` ` `# printing original tuple ` `print` `(` `"The original tuple : "` `+` `str` `(test_tup)) ` ` ` `# Pairwise Addition in Tuples ` `# using tuple() + map() + lambda ` `res ` `=` `tuple` `(` `map` `(` `lambda` `i, j : i ` `+` `j, test_tup[` `1` `:], test_tup[:` `-` `1` `])) ` ` ` `# printing result ` `print` `(` `"Resultant tuple after addition : "` `+` `str` `(res)) ` |

*chevron_right*

*filter_none*

**Output :**

The original tuple : (1, 5, 7, 8, 10) Resultant tuple after addition : (6, 12, 15, 18)

## Recommended Posts:

- Python | Addition of tuples
- Addition in Nested Tuples - Python
- Python | Remove duplicate tuples from list of tuples
- Python | Find the tuples containing the given element from a list of tuples
- Python | Remove tuples from list of tuples if greater than n
- Python | Remove tuples having duplicate first value from given list of tuples
- Python | Count tuples occurrence in list of tuples
- Python | Combining tuples in list of tuples
- Python | Convert string tuples to list tuples
- Python | How to Concatenate tuples to nested tuples
- Python - Filter all uppercase characters Tuples from given list of tuples
- Python program to find Tuples with positive elements in List of tuples
- Python program to find tuples which have all elements divisible by K from a list of tuples
- Python | Rear Addition of Record
- Python program for addition and subtraction of complex numbers
- Python - Specific Range Addition in List
- Python - Diagonal element addition among lists
- Python | Alternate character addition
- Python - Row-wise element Addition in Tuple Matrix
- Python program to create a list of tuples from given list having number and its cube in each tuple

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.