0
Time, I need to format the print of the following class:
class Tupla:
def __init__(self, keys, palavras):
self.keys = list(keys)
self.palavras = list(palavras)
self.op = dict(zip(self.keys, self.palavras))
def __getitem__(self, key):
return self.op[key]
def __repr__(self):
return f'Tabela Completa: {self.op}'
def get_tupla(self, key):
return f'Palavra: {self.op[key]}'
I believe in the method:
def __repr__(self):
return f'Tabela Completa: {self.op}'
I wanted the result to be (For each of the elements of the dictionary):
Key: | Palavra:
Second stage of the question:
def get_pagina(self, num):
to_print = "Key:\t| Palavra:\n"
for item in self.paginas[num]:
to_print += str(item) + "\t\t " + str(self.paginas[item]) + "\n"
return to_print
Where:
aux = list(zip(keys, palavras))
self.paginas = list()
Renan, that’s exactly what it was, obg ! But trying to reproduce your example, I hit another error but this time in a second class, have a look ? I edited the question.
– barrosfilho_
I’m sorry, I just started programming...
– barrosfilho_
What mistake is happening and what you hoped was happening?
– Renan Machado
Well I wanted to print a specific page: Page: {num} | Words: {}
– barrosfilho_
When you do self.pages[num] returns a list of words on that page? If so, start the string with to_print = "Key: {} t | Word: ". format(num) and inside for you will add the words to_print += str(item) + " "
– Renan Machado