Python Data Structures: Big Four Explained

🐍 Python Data Structures: The "Big Four" explained in 60 seconds. ⏲️ ------------------------------------------------------------------------ Mastering data structures is the first step toward writing efficient Python code. Here is a quick breakdown of the Big Four: 👉 List - It is an ordered collection of values of different data type. 🖊️ Ordered - It maintains the order of the data insertion. 🖊️ Changeable - It is mutable so the items in the list can be modified at any time. 🖊️ Duplicate - It can have duplicate values. 🖊️ Heterogeneous - It can have items of different data type. ▶️ my_list = ['Hello', 9000, 3.20, [2, 5, 8]] 👉 Dictionary - It is an ordered collection of unique value stored in key-value pair. 🖊️ Ordered - The item stored in dictionary are ordered without any index value so value can only be accessed with a key. 🖊️ Unique - Every item stored in dictionary have unique keys. 🖊️ Mutable - It is mutable so we can add/modify/delete after creation. ▶️ my_dictionary = {'name': 'Jason', 'position': 'Manager', 'experience': 10} 👉 Set - It is unordered collection of unique value which is unindexed. It is mutable but values are immutable. 🖊️ Unique - It stores unique value. 🖊️ Unindexed - It is unindexed so we cannot access any single item. 🖊️ Unordered - It is unordered so it does not maintain the order of insertion. 🖊️ Mutable Set but Immutable value - It is mutable so item can be added and removed but item are immutable so they cannot be modified. So if we want to modify any item we need to remove the item from the set and add new value. ▶️ my_set = {1, 2, 4, 6, 7, 9} 👉 Tuples - It is collection of items which is ordered, unchangeable and allow duplicate value. 🖊️ Ordered - It maintains the order of the data insertion. 🖊️ Immutable - It is immutable so value cannot be modified after creation. 🖊️ Duplicate - It can have duplicate value. 🖊️ Unchangeable - It is unchangeable so item values cannot be modified. 🖊️ Indexed - It can be accessed using index no. ▶️ my_tuples = ('apple', 'banana', 'orange', 'banana', 'cherry') #Python #PythonProgramming #SoftwareEngineer #PythonTips #LearnToCode

Nice, learnt something new

Like
Reply

To view or add a comment, sign in

Explore content categories