# Revision history [back]

Here are some hints that should be sufficient to solve your problem:

When m is a matrix, you can get all its entries with the list method:

sage: m = random_matrix(ZZ,4,4)
sage: m
[ -1   0  -1  -1]
[ -3   0   1   1]
[ -2   2   1   1]
[  2  -2   3 -12]
sage: m.list()
[-1, 0, -1, -1, -3, 0, 1, 1, -2, 2, 1, 1, 2, -2, 3, -12]


When n is an integer, you can see if it is a square with the is_square method:

sage: n = 4
sage: n.is_square()
True


Here are some hints that should be sufficient to solve your problem:

When m is a matrix, you can get all its entries with the list method:

sage: m = random_matrix(ZZ,4,4)
sage: m
[ -1   0  -1  -1]
[ -3   0   1   1]
[ -2   2   1   1]
[  2  -2   3 -12]
sage: m.list()
[-1, 0, -1, -1, -3, 0, 1, 1, -2, 2, 1, 1, 2, -2, 3, -12]


When n is an integer, you can see if it is a square with the is_square method:

sage: n = 4
sage: n.is_square()
True


You can filter a list with list comprehension, see https://www.pythonforbeginners.com/basics/list-comprehensions-in-python (this is the first link provided by my search engine, there are many ressources on the web about that)

Given a list of integers, you can make the sum with the sum function

sage: sum([1,2,3,4])
10