Built-in data structures that make Python the best for data analysis

Chekwube Utomi
3 min readMar 3, 2023

--

geeksforgeeks.org

Python is a high-level, general purpose programming language developed by Guido van Rossum in 1991. Python is widely used in web programming, process automation and game programming, however, its use in data related tasks is exceptional. The exceptionality is as result the robust built-in data structures, and their associated methods, which makes Python the best data programming language.

List

Have you ever made a list of items to buy when going for shopping? If you have, then, you have a good idea what python list is all about. A list in python parlance is a collection of items enclosed in square brackets. One important feature of a list is mutability which means that after a list has been declared, its content can be changed. A list of items to shop can be declared as follows:

items = ["shirt", "shoes", "watch", "necklace", "pants"]

The above list has five names, so we say that the length is 5. Each item in a list has an index starting from 0. That is the index of “shirt” is 0; while the index of “pant” is 4.

The items in a list are referenced using the indexes:

item[0] # references shirt
item[3] # references necklace

Tuple

Tuple is another built-in data structure in python that is similar to list in all aspect apart from immutability. Tuples comes to play when you want your data collection to be unchangeable and secured. Items in a tuple are enclosed in parentheses. We can declare a tuple of shopped items as follows:

items = ("shirt", "shoe", "watch", "necklace", "pant")

Items in a tuple are indexed and referenced the same way as that of a list.

Dictionary

The data structure I like most in python is dictionary. A dictionary is a collection of key-value pairs. Items in a dictionary are enclosed within curly brackets. We can declare a dictionary of items to shop with their price as follows:

items = {"shirt": "$30", "shoe" : "$250", "watch" : "$300", 
"necklace" : "$120", "pant" : "$200"}

In the above dictionary, the items are the key while the prices are the values. Values of a dictionary are referenced using the key. For example:

items["shirt"] # references $30
items["pant"] # references $200

Sets

The last data structure to be discussed is set. It is a unique and non-sequential collection items. Anytime you want your collection to be without repetition, set is the right structure for the task. Since the items in a set are not sequential, they are not indexed. Just like a dictionary, the items in a set are enclosed using curly brackets as follows:

items = {"shirt", "shoe", "watch", "necklace", "pant"}

Final words

The built-in data structures in python are powerful and have made python the choice language for data tasks. Apart from the built-in data structures, there are other third party libraries like Pandas and Numpy that have more sophisticated data structures.

For more blogs on python development, please follow me on Medium and Linkedin.

--

--