💥Don't Forget to Subscribe to my Channel! 💥
/ @practicalpythonsolutions-b4478
--------------------
Lesson 7 goes over the basics of Python Dictionaries
Dictionaries in Python are
sets of key value pairs. The data is
usually managed by the key and the value
can be anything: a tuple, lists
Or practically any data type. Dictionaries
are used quite commonly in Python and
they allow you to connect related data
so why do you need to use a dictionary python, when you already know how to store values in a list?
Well, you use a list to store a sequential list of values, but a dictionary is similar to a
Conventional dictionary in that it stores keys with references. Easiest way it to think of them a
Phone book, if anyone can remember what that was. A person’s name is the key
And the value is the phone number. If you have the name, you can find the number. And that is why you use a dictionary in python…. to store a mutable or changeable collection of data values.
We are going to learn how to create them, delete, add and sort through
dictionaries.
To create a list that was
on the previous slide, you would simply
type "Breakfast equal to the following keys and values. The key value pairs
Would be surrounded by the Curley brackets - these brackets define a
dictionary. There is typically one key that has one or more values associated.
The key in this case is "ham" and the value is "yes." For the next key-value pair: the key is "EGGS"
and the value is "Yes." This is obviously a
Monty Python reference but the point is that the
keys are on the Left and the
value or values are on the right of the colon (:).
This is typical dictionary that you would use in
a program. Dictionaries are frequently used to store data on an object
and key-value pairs are associated with each other.
An example would be a data object in a game. It could be an alien, a
zombie or moving duck ... whatever the object is, it needs
persistent data or settings associated with it. Typically
this information on the object would be
tracked in a dictionary. Data on the object could
include the color, speed, points and
the coordinates for example.
Dictionaries, when you look at them
first, might not appear to be that
important but they are and not just game
development but all sorts of data
parsing - so dictionaries are extremely
valuable.
Смотрите видео Lesson 7 - Python Dictionaries (Basics) онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Practical Python Solutions 31 Май 2020, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 106 раз и оно понравилось 5 людям.