Practice 4 - Dictionaries and doubles

Hello, I have a bit of trouble understanding how dictionaries actually work. Below is my resume of understanding but I have some questions regarding how “For each” and new dictionary is settled.

  1. citylist - is not clear what is the purpose
  2. how weight is computed?

Thank you in advance!

The dictionary keeps your 2 columned data in key and value pair. you can access the value by using the key.

I the snap. the cities are the keys and weight will be the value

Thank you for quick answer. What I do not understand is why I need citylist and what is the purpose of it. Because I have also a new dictionary called “Cities”. Can you give me an example of how this itineration works?

as per the screenshot “citylist” and “cities” both are same. They both map city to weigfght.

What is the requirement? What you want to achieve by using dictionary?

the purpose is to compute the weight based on each city selected by user

Then let us simply understand this.

The Name and City is already there in the column, we need to calculate the 3rd column as per the data in “city” column.

So to do that we have a dictionary(citylist), in which we pass the city name as key and get the weight value corresponding to that city.

if you type row(“Madrid”).tostring, this will give you 2,1 as output value

Here the dictionary stores the 2 columned data in key-value pair, this helps in quick extraction of data.

Hope this helps. Also suggest you to watch some videos to get more idea if required

Thank you very much, really useful!

1 Like