-2
Full 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]}'
Where Keys and words are two np.arrays.
dados = pd.read_csv('C:/Users/afons/Downloads/words.txt', error_bad_lines=False)
Creating array with all the words of the file through numpy and shuffling
listaPalavras = np.array(dados.values)
np.random.shuffle(listaPalavras)
Creating array with Keys and shuffling
listaIndices = np.array(range(len(listaPalavras)))
np.random.shuffle(listaIndices)
Creating the table of tuples
tabela = Tupla(listaIndices, listaPalavras)
Why create the array if
pd.read_csv('C:/Users/afons/Downloads/words.txt', error_bad_lines=False)
gives you back aDataframe
. Doprint(dados)
here comes all the information obtained from the CSV.– Augusto Vasques
But the question is how to print the complete "self.op" which is a Dict, where I join the words of "data" with a random key from another list. In the tuple class ...
– barrosfilho_