Your dictionary is "backwards".
The correct is not to use a dictionary so that the values are lists and each position in the lists, in all values in the dictionary, corresponds to a record (that is: the set of information relating to an object).
The correct is to have a list, where each element in the list is a dictionary, and then all the information in your record comes together.
In case, you would have something like:
imoveis_cadastrados = [
{'Codigo': 123 'CPF_PROP': None, 'Tipo': None, 'Endereço': None, 'Valor_Aluguel': None, 'Status_Aluguel': 'N'},
{'Codigo': 321, 'CPF_PROP': None, 'Tipo': None, 'Endereço': None, 'Valor_Aluguel': None, 'Status_Aluguel': 'N'}
]
there, ready.
You can do a linear search doing something like this:
imovel = [im for im in imoveis_cadastrados if im["código"] == 321]
imovel["Status_Aluguel"] = "S"
If you always want to locate by code, you can use the outside structure as a dictionary, where the key is always the code - there you don’t need the "Code" key in the inside dictionaries:
imoveis_cadastrados = {123: {'CPF_PROP': None, 'Tipo': None, 'Endereço': None, 'Valor_Aluguel': None, 'Status_Aluguel': 'N'},
321: {'CPF_PROP': None, 'Tipo': None, 'Endereço': None, 'Valor_Aluguel': None, 'Status_Aluguel': 'N'}}
And to change the status of a property, given the code:
imoveis_cadastrados[321]["Status_Aluguel"] = "S"
If you need to locate furniture by different code criteria, such as "list all properties of CPF xxxx", then it is best to use an SQL structure instead of dictionaries.
Python comes with the built-in sqlite database, which can store the data in memory, which would have the equivalent behavior of a dictionary, but can also store the values in a file, which will be kept synchronized. If your problem is part of a real program you are doing, saving your data in a file is something you will want to do anyway.
And the advantage of using SQL in this case is less being any kind of efficiency cariterio - unless you’re going to have a registry with tens of thousands of properties, and yes, because the SQL language allows you to express these searches in a natural way. (Although the recommendation for real projects is, take another step and use a "wrapper" for SQL, and use everything as Python classes, with the help of an ORM like Sqlalchemy or the Django framework)
another tip, unrelated to your problem - a matter of style, but one that is very practical: do not use names by mixed uppercase and lowercase And underscores - will only give you trouble to type, and are difficult to read - everything in lowercase is more enjoyable to read - and, when displaying in the user interface, there are functions like the method
.title
of strings that can turn initials into uppercase if you find it interesting.– jsbueno