Python | Multiply elements of Tuple

Given, a list of tuples, the task is to multiply the elements of the tuple and return list of the multiplied elements.

Examples:

Input: [(2, 3), (4, 5), (6, 7), (2, 8)]
Output: [6, 20, 42, 16]



Input: [(11, 22), (33, 55), (55, 77), (11, 44)]
Output: [242, 1815, 4235, 484]

There are multiple ways to multiply elements of a tuple. Let’s see a couple of them.

# Method 1: Using Iteration
This is the most naive method to achieve a solution to this task. In this, we iterate over the whole list of tuples and multiply the elements in each tuple to get the list of elements.

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python code to convert list of tuple into list of elements
# formed by multiplying elements of tuple.
  
# Input list initialisation
Input = [(2, 3), (4, 5), (6, 7), (2, 8)]
  
# Output list initialisation
Output = []
  
# Iteration to multiply element and append multiplied element in 
# new list
for elem in Input:
    temp = elem[0]*elem[1]
    Output.append(temp)
  
# printing output
print("The original list of tuple is ")
print(Input)
  
print("\nThe answer is")
print(Output)

chevron_right


Output:

The original list of tuple is 
[(2, 3), (4, 5), (6, 7), (2, 8)]

The answer is
[6, 20, 42, 16]

# Method 2: Using list comprehension
This is the one-liner approach to achieve the solution to this task.

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python code to convert list of tuple into list of elements
# formed by multiplying elements of tuple.
  
# Input list initialisation
Input = [(2, 3), (4, 5), (6, 7), (2, 8)]
  
# Iteration to multiply element and append multiplied element in 
# new list
Output = [(x * y) for x, y in Input]
  
# printing output
print("The original list of tuple is ")
print(Input)
  
print("\nThe answer is")
print(Output)

chevron_right


Output:

The original list of tuple is 
[(2, 3), (4, 5), (6, 7), (2, 8)]

The answer is
[6, 20, 42, 16]


My Personal Notes arrow_drop_up


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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.