LOVE dictionaries is there any reason to use lists?

Hey there folks :slight_smile:
so on my third section of Dictionaries and Frequency Tables. I really like the fact that I can find a piece of info not based on its index position but based on fx. rating or something which I personally find meaningful. I think I will gravitate towards dictionaries instead of lists especially with big datasets. Is there any reason why I cannot just use dictionaries instead of lists, persistently in real live settings?

Hey @lindamacdonalde,
I am really happy that you are thinking insight about the topics you learned. Yes, all the basic data structure like list, dictionary, tuple have individual reasons to use.
It’s great, you are thinking about the list and dictionary.

Dictionaries are basically hash tables, you use to store pairs of key->value, having fast access to the value knowing the key. You can think of a dictionary as a list of tuples (key,value) with a fast function that can give you the index of an element given the key.

Suppose, I am Zubair and you are my teacher. You want to store all the students’ grades along with me. You can do it either in the dictionary and list. If you do it with the help of the list according to the order of the students, you can easily track it by the index number. On the other hand, you can do it with the dictionary through the name/ order of the students.
Both of the above cases is okay. But think a while list will take a few memory as it does not store any key and iteration process is also easy in the list.
So, we need to decide when we will use the list and dictionary.

2 Likes

hey there thanks for this :slight_smile: I thought their might be some sort of advantage to the lists :wink: is there a section on how we optimize our code in general?

Thanks @lindamacdonalde. I think you are learning in our platform. You will get all the rest of the answers of your question in the next step. If you find the above post as your question answer, mark the reply as solution.

1 Like

Hey Linda, you might like reading through these articles about dictionaries and lists.

2 Likes