second day, what is a dictionary in python

we've ended with What is data science on the first day. therefore, it was a pretty good topic. then we started with Python and learn about Python, which I've been learning for 1 year, So I skimmed many topics like data storage and variable, but I stuck with a dictionary, anyway why we should use a dictionary beside lists? this question stuck in my head for a long time.

here I will clarify for you why the dictionary is useful and when we can use it.

A dictionary has several advantages over a list, especially in Python. Dictionaries have two parts to every entry the key and the value and these are stored as pairs. This can give you more flexibility when storing data.

  1. to understand how a dictionary works in Python we should understand why lists do not effort or be suitable to solve the problem.

    One example would be storing the age of school students. You could store the age and name as a value and key pair. This would allow you to sort the dictionary for a particular student and retrieve their age. To do this with lists you would require two lists to search through or a very complicated indexing system.

  2. A dictionary has several advantages over a list, especially in Python. Dictionaries have two parts to every entry the key and the value and these are stored as pairs. This can give you more flexibility when storing data

here is the answer from StackOverflow: https://stackoverflow.com/a/3489100

what is a list?

Lists are used to store multiple items in a single variable, it keep data Ordered. you can add, and remove items in a list after it has been created.

mylist = ["apple", "banana", "cherry"]


what is a dictionary?

thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 }

Dictionary items are ordered, changeable, and do not allow duplicates. Items can be referred to by using the key name.