Skip to content
Advertisement

How can you select a specific dictionary by id in order to update its contents(Python)? [closed]

JavaScript

Hello, I have to create a program that is able to add a transaction with the following details: day, sum, and type. I don’t know how many transactions there will be so I found a code that I adapted to match my needs. In the last part of my code I want to try to update a specific dictionary (for example, if the user wants to modify the amount in a transaction with the id of 1, I should select that specific dictionary and modify it). I am a beginner in Python, but I have some knowledge regarding programming overall. Thanks in advance!

Advertisement

Answer

In your code, cont is already a dictionary, you just have to replicate the same behaviour for the other dictionaries.

So for example, after the user input the program its transaction id (in tranz) and the sum in z, you could do something like this to edit only the sum:

JavaScript

Be aware that this is going to work only if you already set cont[tranz] as a dict (you do it already in your range(0, n) cycle)

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement