Tabulate Python

Asked

Viewed 106 times

-3

from tabulate import tabulate

data = {
    'Clients': ['Vini'],
    'Foods' : ['Coca'],
    'Drinks' : ['Pitu']
}

data['Clients'] = input('Digite: ')

print(tabulate(data, headers='keys', tablefmt='pretty'))

I have a question in this ICT, I wanted to add elements there with the input, but when I try, remember it is printado character by character one below the other, and not in line, anyone has how to help there? if there’s a way.

2 answers

0


You must exchange data['Clients'] = input('Digite: ') for data['Clients'].append(input('Digite: ')) , this way you will add a new account and will not skip line

Code with while True:

from tabulate import tabulate

data = {
    'Clients': ['Vini'],
    'Foods' : ['Coca'],
    'Drinks' : ['Pitu']
}

while (True):
    data['Clients'].append(input('Digite: '))
    print(tabulate(data, headers='keys', tablefmt='pretty'))
  • Thanks Natan, but a doubt, could I keep the elements ? for example, I put this block of code in a while True, and wanted each added element to continue to be stored there, however the . append just replaces.. have any method that makes it possible to do this? if it has not been explained too much let me know that I try to send the idea aq

  • You probably put the data = { ... while also, that is, whenever you put something new, it goes back to its original state. I edited my answer by putting while True

0

inserir a descrição da imagem aqui

Show, worked out here, I managed to store the data in while True

Browser other questions tagged

You are not signed in. Login or sign up in order to post.