On Wednesday, 11 September 2019 20:11:21 UTC+10, Sayth Renshaw  wrote:
> Hi
> 
> I want to allow as many lists as needed to be passed into a function.
> But how can I determine how many lists have been passed in?
> 
> I expected this to return 3 but it only returned 1.
> 
> matrix1 = [[1, -2], [-3, 4],]
> matrix2 = [[2, -1], [0, -1]]
> matrix3 = [[2, -1], [0, -1]]
> # print(add(matrix1, matrix2))
> 
> def add(*matrix):
>     print(len(locals()))
> 
> add(matrix1,matrix2,matrix3)
> 
> Cheers
> 
> Sayth

Tried creating a list of the arguments, however I am creating too many 
positional arguments.

matrix1 = [[1, -2], [-3, 4],]
matrix2 = [[2, -1], [0, -1]]
matrix3 = [[2, -1], [0, -1]]

matrix = []
def add_many(a = list(*matrix)):
    for num in a:
        for i in range(len(matrix[num])):
            for j in range(len(matrix[num])):
                print(matrix[num][i][j] + matrix[num][i][j])

add_many(matrix1,matrix2)
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to