This Data Structure Is Underrated!

Categories: General, Tech | Pubby Cash Received:  0 | Click to Award

Let’s say that you needed to create a list of all the users that have been banned on your site. Many programmers would just use a list, and that’s just fine. They would insert a tuple containing information about the first user and the time banned, then continue with the second user and their time banned, and so on. If they want to remove a user from the list, they could either use ‘pop’ or ‘remove’. Additionally, if they want to update an item in a list, it can be very difficult because there might be multiple items with the same name. Basically, using a list isn’t the best way to go when it comes to storing lots of data that is easily accessible. So is there an even easier way? The answer is yes. Dictionaries are very beneficial in this situation because each item stored in a dictionary is unique. If you want to remove an item from a dictionary, all you have to do is find the key and delete it using the ‘del’ keyword followed by the name of the key. It’s that simple. And if you want to update an item in a dictionary, you can simply call that item using it’s key and set that to your new value. Many programmers underestimate the power of dictionaries and often turn to lists because dictionaries are just a little more confusing. But trust me, once you get the hang of dictionaries, storing data will feel like a breeze.


Published from: Pennsylvania US
Liked by: H2O, Evan Tang, fnfOzvSR 

Daily Deals


MECHANICSBURG WEATHER