When there are so much data you have to store, you don’t wanna store it by running the call tinyDB store
block. Therefore, the dictionary component comes in handy.
What is a dictionary?
Dictionary is a built-in component.
Generally speaking, a dictionary uses a key to call and get the value.
For example,
It will return the string "whatever"
.
How to use it?
As mentioned,
a dictionary uses a key to call and get the value.
What you’ll need:
The same logic as TinyDB, but we use the dictionary this time
The dictionary now acts like tinyDB, which can be used to store almost every type of value.
How to get the value?
Using the example above,
if the key doesn’t exist, return “not found”.
How to store/ add new value?
Storing new value:
If you want to replace with/ add a new value, you can do the following.
Remember to store the dictionary in tinyDB as well.
Adding new value:
Similar to storing a new value, but this creates a new pair of key and value.
There are also many features in the dictionary such as return the list of key and value, and more complex algorithm can be performed easily with dictionary.
If you find it helpful, kindly leave a like : )
Don’t hesitate to ask any questions, I will try to answer as much as I can.