Skip to content

Instantly share code, notes, and snippets.

@alfredoem
Last active April 18, 2021 00:17
Show Gist options
  • Save alfredoem/0e7e25fb67cc690ac41234ccf278a2e1 to your computer and use it in GitHub Desktop.
Save alfredoem/0e7e25fb67cc690ac41234ccf278a2e1 to your computer and use it in GitHub Desktop.
Python Collection Example
listacol = {}
listacol['1111'] = {
'name': 'Greed',
'country_name': 'PERU',
'state': 'Utha'
}
listacol['2222'] = {
'name': 'Cloud',
'country_name': 'RUSIA',
'state': 'California'
}
def show_all(lista):
head = 'PROPERTY/PERSON \t\t'
row_country = 'COUNTRY \t\t\t\t'
row_state = 'STATE \t\t\t\t\t'
for item in lista:
head += '{}\t'.format(lista[item]['name'].upper())
row_country += '{}\t'.format(lista[item]['country_name'].upper())
row_state += '{}\t'.format(lista[item]['state'].upper())
print(head)
print(row_country)
print(row_state)
option = ''
while option != 'salir':
option = input("Que acción desea realiza? editar|salir|mostrar\n")
if option == 'editar':
id = input('Ingrese el ID a editar \n')
listacol[id] = {
'name': input('Ingrese el nombre\n'),
'country_name': input('Ingrese el código de país\n'),
'state': input('Ingrese el estado\n')
}
elif option == 'mostrar':
show_all(listacol)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment