1

I have several list that are multiplied between them and with external variables, for example:

list_1 = [1, 2, 3, 4]
list_2 = [2, 1, 2, 1]
var_1 = 2
var_2 = 3

I need to multiply list values one by one expecting the following result:

result = list_1 * list_2 * var_1 * var_4  
#  Result = [12,  12, 36, 24]

I know this can be made with a list comprehension, for example:

result = [var_1 * var_2 * a * b for a, b in zip(list_1, list_2)]

The problem with list comprehension is that somethings var_1 and var_2 are lists, and they need to be in the zip arguments. Another problem is that the number of lists is large and the code looks ugly.

Another solution is numpy arrays, but I want to do this with classic python lists.

What I want is extend the python list, and override some method to change the product behavior, it is posible?

Eduardo
  • 687
  • 1
  • 6
  • 24

0 Answers0