Simple use of dictionary and TinyDB

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".
blocks (2)

How to use it?

As mentioned,

a dictionary uses a key to call and get the value.

What you’ll need:

image
image

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.

49 Likes

Nice guide @WatermelonIce :+1:

5 Likes

Simple and understandable explained guide, @WatermelonIce! That gives you
:+1: :+1: :+1:
You made a Tutorial of blocks which are very very useful and must be understood correctly. Thank you very much!
:partying_face: :sunglasses:

3 Likes

Useful Tutorial. Keep it up…

2 Likes

I changed your title a bit since it is a combination of a Dictionary and a TinyDB. Hope you don’t mind.

5 Likes

Can I Store Html Text as pair?

1 Like

I think you can. What about just trying it out? :sweat_smile:

1 Like

As Yoshi said, what are you trying?
You want the key to be html or the value?
As mentioned,

Text can always be stored.

1 Like

Good guide @WatermelonIce :golfing_man:

2 Likes

Nice guide. Easy to understand. Great work

1 Like

very , very helpful! thank you very much for the tutorial! 10 thumbs up!!!

1 Like

Hello do we have to make the dictionnary each time the app is launched or is it persistant like TinyDB ?

In therm of performance what is the quicker way to get a value between dictionnay, TinyDB or Ressource Utilities (using GetString from blcok) ?

Thanks for the reply :wink:

Dictionary won’t save anything in the storage. You need tinyDB for that.

For resource utilities, that’s for json file, most probably the json file you put in assets

Ok so need to remake the dictionnary at each launch.

I have a JSON file for all my value and need to acces them :

  • make a dictionnary with all the values from the json
  • put all values from json in TinyDB
  • load the json in a resource utilities

And what is the most efficient during the app use between these 3 methods ?

Great Guide !! :+1:

1 Like

What wrong with my blocks, when run app, screen turn to “white screen”, there is nothing …blocks(3)

Is “http://azparts.epizy.com/blix/index.html” in your dictionary as a key?

i’ve tried http://azparts.epizy.com/blix/index.html is a key, and http://azparts.epizy.com/blix/index.html is a value, but it still dont work.

In this case you should put http://azparts.epizy.com/blix/index.html in key, and the url you want to go in value.

However, would you be redirected to other website when the page is loaded?

This all my blocks, 4 links in key i want it direct to 4 value.
when i open app, screen turn to “white screen” and nothings happen.blocks(3)