Now, let us understand some differences between the dictionaries and the list.
Now dictionaries are like lists in many ways, but there are a few important differences.
Point number one is dictionary items are not in any order.
There is no Forestar last item in dictionary as there is no list.
Second, as you can't concatenate dictionaries with the plus operator, if you want to add a new item,
use indexing with the new TODAS list.
Only have integer index values that range from zero to the length of the list minus one.
But dictionaries can use any keys if you have a dictionary stored in a variable state where one you
can store of value in where at the index.
Three without needing values of the word zero or one or two.
OK, now coming to adding or changing the items in the dictionary, you can also add or change value
in a dictionary by using the dictionary.
Giesen indexes.
OK, for example, if we try to see the dictionary three is equal to we are giving here C then and the
value for the same item.
OK, now we are giving a print command and we are saying here dictionary three at the index, then we
get the value print.
Similarly, if we just say dictionary three and the index then is equal to say hacking, OK, and now
we give up and command saying dictionary three index, then we get the value hacking.
So this dictionary has an existing dictionary string value associated with the Gaetane that is Python,
and we can assign a new value hacking to that using the same dictionary three and the index then.
OK, now moving to using the land function with dictionaries.
Now the land function shows the number of items in the list or the number of characters in a string.
It can also show you a number of items in a dictionary.
Also, for example, will enter something, an interactive shell to see how to use the land function
to count items in dictionary, for example.
Now we create a dictionary for and that is just open closed bracket.
If we now use Lentulov Dictionary for
megadeal and that's zero.
Now suppose we say a dictionary for we give your key value see first and we give your value.
C, a, b, c, ok.
Now if we say another dictionary for C second as the key and the value for that is X, Y, Z, OK,
we add another dictionary for the total and the value for that is eleven.
OK, and now we give length of dictionary for we get that Dylanesque three.
So the first line in this shows an empty dictionary.
OK, the line function correctly shows the length of this empty dictionary as zero.
However, after we introduce the following three values into the dictionary, the length function outdance
three for the trachea and value base that we have just assigned to the variables.
Let's move on to using the operator with the dictionary.
Then you can also use the interpreter to see whether a certain key exists in the dictionary.
And it's important to remember that the interpreter Chayefsky's are not values.
OK to see this operator in action.
We will enter the following an interactive shell for example.
We creates a dictionary five.
And here we give C one and colon C first item.
Gamma C two.
Second key.
Colon C second item.
OK, that is the values we have given.
Now we give here for example the key C one in dictionary five.
It gives us true or we give to in the dictionary five piguet true.
Or if we give three in dictionary five it does fall because that is not existing.
Right.
Similarly if we give for example, C for not in dictionary five, that's true.
So in this case, we have set up a dictionary called Dictionary Five with some key value pairs and then
checks whether the key exists in the dictionary, using the interpreter, wherever it is existing,
it gives us the value proof, wherever it does not forget the value is false.
OK, similarly feels not an operative word.
The value is not existing in the dictionary.
We again get the value of the existing commander.
Through not coming to finding the items is faster with a dictionary than what list.
So now let us create a list and a dictionary.
OK, now, for example, let's create your own list, one that is equal to see fighting one war hacking
C.
Intermediate and recreate dictionary six, that's equal to we are giving your say, let's give value.
We will change the keys.
So let's give Saiki one as zero.
Then let's give key to and that is also zero.
And then let's give you three.
And that is also zero.
OK, now.
Python can basically evaluate the expression, that is, if you give a particular value in the dictionary
value, which is more faster retrieval than your list value.
OK, now this is basically because for a list, Python must start at the beginning of the list and then
move through each item in order until to find a particular item.
If the list is very large, Python must sort through numerous items.
A process can take a lot of time.
What a dictionary is also called as a hash table directly translates where the computer's memory and
the value for the key value is stored.
Which is why dictionary items don't have an order no matter how large a dictionary is.
Finding any item always take some amount of time, same amount of time, because this difference is
speed that is hardly noticeable when searching a short list or short dictionaries for that case.
OK, now let us understand using the loops for dictionaries so you can also iterate over those keys
in the dictionary using for loops, just as you can get rid of the items in the list.
OK, now, for example, we have this dictionary six created, which takes four key one in dictionary
six.
OK, and here we give print command and we give print the value of given and dictionary six.
Add the index geva so we get that given value.
Zero two zero three is also zero.
So all the values are being printed.
OK, so to use a false statement to iterate over the keys in a dictionary starts with the four key word
against the variable key one using the N word to specify that you want to loop over the dictionary six
and end the statement with the column.
So as you can see, after entering the print, come on, it returns each in the dictionary along with
its corresponding values.