Python Data Structures. Part 1…

Farida Aliyeva
3 min readNov 30, 2020


According to resources, in Computer Science data structure is a data organization, management, and storage format which enables efficient access and modification. You can also refer to it as a collection of data values, their relationships, and the functions that can be applied to that data values. They are a vital part of software development. Proper choice of data structure is a very crucial step in the development process.

So, considering all the importance of data structures and their implementation I decided to write the following blog post where various Python data structures are introduced and discussed.

Data Camp Intro to Python Data Science

In the following blog post, I would like to dive deep and discuss more of the non-primitive data structures of Python.

Non-Primitive Data Structures

These are the complex representatives of the data structure family. They primarily store a collection of values in their various formats.

So, let us list some non-primitive Python data structures, which are: Arrays, Lists, Files.


Arrays in Python are a compact way of collecting basic data types, all the entries in an array must be homogenous (of the same type). Unlike other programming languages (C++ or Java), arrays are not that popular in Python.

Generally, talking of arrays in Python, you refer to lists. However, there is a fundamental difference between them. Lists can consist of elements belonging to different data types, cannot directly handle arithmetic operations. but due to flexibility, it allows easy modification of data.

In Python, arrays are supported by the Array module and need to be imported before you start initializing and using them. The elements stored in an array are constrained in their data type.

For more information about functionalities refer to Python Array Documentation.


Lists in Python are used to store a collection of heterogeneous items. They are mutable, which means that you can change their content without changing their identity. Lists are built into Python: you do not need to invoke them separately.

This is how we define lists

Python provides many methods to manipulate lists. Adding new items to a list, removing some items from a list, sorting, reversing a list are common manipulations.

some examples on list manipulations


One of the traditional parts of the data structures is files. It is essential for a programming language to have the capability to store and retrieve previously stored information. Python has several functions for creating, reading, updating, and deleting files.

The syntax to read and write files in Python is similar to other programming languages but a lot easier to handle. Some common functions:

  1. open()- opens file in a system
  2. read()- reads entire file
  3. readline()- reads file by line
  4. write()- write to a file
  5. close()- close the file
some examples

We can see in the first function that it has some additional argument which is the file mode. With this mode, you can specify whether you want to read (r), write (w), append (a), or perform both of the operations read and write (r+).

That is all for the first part, thank you for your precious time! The next part of the blog post will contain more coding examples and discuss Tuples, Dictionary, Sets, Trees, Stacks, and probably some more. :) See you soon………



Farida Aliyeva

Data Scientist at SDH | MS Graduate in Computer Science and Data Analytics