Photo by Timon Klauser on Unsplash

Data Structures in Python

Get proficient with lists — Python’s most versatile data structure

Ankit Gupta
Towards Data Science
15 min readAug 21, 2020

--

This article is about lists. They are the most versatile and resourceful, in-built data structure in Python. They can simultaneously hold heterogeneous data i.e., integers, floats, strings, NaN, Booleans, functions, etc. within the same list. They are an ordered sequence of items that means the order of the elements is preserved while accessing lists. They are mutable i.e., you can change (add, delete, modify) any item in the list. They can hold duplicate items unlike “sets” — another data structure in Python.

After reading this article, you will gain a clear understanding and ability to work at an advanced level with Python lists.

I will cover the following topics:

  • Creating a list and adding elements
  • Accessing list elements
  • Removing list elements
  • Inserting elements
  • List arithmetic
  • Reversing a list
  • Sorting a list
  • Index of an item
  • Counting item frequency in a list
  • List comprehensions
  • Copying a list
  • Nested lists

--

--

Data Scientist | Computational Materials Scientist (PhD) | Tech Writer | Stack Overflow Contributor for Python and Matplotlib