Sayth Renshaw schreef op 11/09/2019 om 12:11:
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()))

May I suggest renaming matrix to matrices or matrix_list or something? I find that much clearer to read and understand: singular for one object, plural for a collection of objects.


def add(*matrices):
    print(len(matrices))

--
"Honest criticism is hard to take, particularly from a relative, a
friend, an acquaintance, or a stranger."
        -- Franklin P. Jones

Roel Schroeven

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to