Working with Python Lists: a Cheatsheet

Methods, functions and use cases of Python lists

--

After writing a few pieces on topics like econometrics, logistic regression and regularization — I’m back to the basics!

Many sophisticated data science algorithms are built with simple building blocks. How quickly you will level up your skills largely depends on how strong is your foundation. In the next few articles, I’ll touch upon a few such foundational topics. Hopefully, learning those topics will make your journey a pleasant and fun experience.

Today’s topic is Python lists.

Most people would learn tools first and then practice them with a few examples. I take the opposite route — focus on problems first, and along the way learn tools, methods and functions to solve them. As such, today’s article is broken down into the following small pieces:

  • what are lists and how to create them
  • how to add/remove elements
  • how to access list items, and finally
  • what operations to perform on them

What is a list?

Let’s start with a familiar example — a grocery list.

Apple, banana, milk, sugar, salt — that’s a grocery list I might write down on a…

--

--