Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

Follow publication

Epacris — The List Methods in Python

A new acronym to remember Python list methods.

Srikanth Potukuchi
Python in Plain English
3 min readFeb 7, 2022

--

Epacris is actually a word and it defines a genus of about forty species of flowering plants in the family Ericaceae.¹

What’s that got to do with Python Lists? Well if you look closely, the acronym EPACRIS covers all the list methods. I often find it annoying to look up the list methods and found a way to remember them all. Let’s start.

E — extend()

As the name suggests, we can add more elements to the end of an existing list.

Example:

P — pop()

Remove elements from specified position.

Example:

A — append()

Add elements to the end of the list. Notice below the difference between extend and append.

Example:

C — clear(),copy(),count()

clear() — removes all the elements from a list

copy() — makes a copy of the original list. What’s the advantage? See the below example, when we make changes to LM then LM3 also changes but LM2 doesn’t.

count() — counting the occurrence of an element in a list.

Example:

R — remove(),reverse()

remove()- removes the first occurrence of an element from the list

reverse()- reverse the elements of a list

Example:

I — index(), insert()

--

--

Published in Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

Written by Srikanth Potukuchi

I am working as a Lead Data Scientist in Canada. Passionate about data science since 2014. I started with SQL , R and SAS; later picked up Python.

No responses yet

Write a response