Database in tuple

1

I need a code that receives data (values) and prints them according to its key. Each entry corresponds to a hypothetical person's data, which contains Age, Name, Sex, Marital Status, Number of friends and Number of Photos. I am writing using a dictionary that takes the inputs as values and relates them to the keys. How to do this using Tuples and so that the data is printed in the order they were supplied by the user? How I am doing:

Dados = dict()
entrada1 = raw_input()
entrada2 = raw_input()
entrada3 = raw_input()
entrada4 = raw_input()
entrada5 = raw_input()
entrada6 = raw_input()
Dados['Idade'] = entrada1
Dados['Nome'] = entrada2
Dados['Sexo'] = entrada3
Dados['Estado'] = entrada4
Dados['Amigos'] = entrada5
Dados['Fotos'] = entrada6
for chave, valor in Dados.items():
    print chave, valor

In addition, the code is not printing the keys and values so that one data appears per line, but by printing the entire dictionary.

    
asked by anonymous 27.04.2016 / 15:09

1 answer

1

The simplest way is to use OrderedDict rather than embedded%% - dict is a dictionary-like data structure, available in module OrderedDict of the default library - but unlike a dictionary normal, preserves the order in which the key and value pairs were created when interacting with it.

In this way, all you have to do in your program is to import the OrderedDict and declare collections to be one of them - the rest you can leave as is:

from collections import OrderedDict
Dados = OrderedDict()
...
    
28.04.2016 / 01:25