Python tuple program to compute the element-wise sum of tuples

In this python tuple program, we will compute the element-wise sum of tuples.

Steps to solve the program
  1. Take 3 tuples as input.
  2. Use the map() function and inside the map function use sum and combine the tuples using zip() to compute the element-wise sum of tuples.
  3. Convert the output from the map function to a tuple using tuple().
  4. Print the output.
				
					a = (1, 6, 7)
b = (4, 3, 0)
c = (2, 6, 8)
print(f"Original tuples: {a},{b},{c}")
s1 = map(sum, zip(a,b,c))
result = tuple(s1)
    
print("Element wise sum of the given tuples: ",result)
				
			

Output :

				
					Original tuples: (1, 6, 7),(4, 3, 0),(2, 6, 8)
Element wise sum of the given tuples:  (7, 15, 15)
				
			

convert a given tuple of integers into a number.

convert a given list of tuples to a list of lists.

Leave a Comment