21.12.2022 Views

python_para_desenvolvedores_2ed

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

130 Sobrecarga de operadores

Seleciona linhas da matriz

"""

r = []

for x in xrange(x1, x2 + 1):

r.append(self.row(x))

return r

def index(self, xy):

i = 0

for item in self.itens:

if xy == item[0]:

return i

i += 1

else:

return None

def dim(self):

"""

Retorna as dimensões atuais da matriz

"""

x = y = 0

for xy, data in self.itens:

if xy[0] > x: x = xy[0]

if xy[1] > y: y = xy[1]

return x, y

def keys(self):

"""

Retorna as coordenadas preenchidas

"""

return [xy for xy, data in self.itens]

def values(self):

"""

Retorna os valores preenchidos

"""

return [data for xy, data in self.itens]

def row(self, x):

"""

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!