← Back to list

5 Python List Functions That Changed The Way I Code

I still remember when I started learning Python. I only used lists to store things like numbers, strings, or even other lists.

Kiran Grewal in Python in Plain English · 2025-01-05 00:38 · 311 claps · 3.9 min read paywalled
#python #python-programming #future-developers #python-list #python-functions
Open on Medium ↗
Wiki topics: GEN · Genomics & Sequencing EDU · Education & Learning 💻 · Programming

5 Python List Functions That Changed The Way I Code

I still remember when I started learning Python. I only used lists to store things like numbers, strings, or even other lists.

At that time, I didn’t know that its functionalities were much more than this. Then, I found amazing Python list functions.

Image generated by AI

Image generated by AI

These functions made my code shorter and easier to read. So, if you are just a beginner right now, then these list functions are super important to understand. So that you don’t make the same mistake that I made.

So, without wasting much of your time, let’s dive into these.

Not a medium member, yet? Read it FREE here.

1. enumerate(): Write Clean and Easy Loops

Before I didn't know about enumerate(), so I usually used loops like this:

my_list = ['apple', 'banana', 'cherry']  
for i in range(len(my_list)):  
    print(i, my_list[i])

This works, but it feels like something can be much better. Then, I learn about enumerate().

You might be thinking what it does. It allows us to get the index and the value of each item in the list at the same time:

for index, value in enumerate(my_list):  
    print(index, value)

As you can see, my code looks shorter and more easier to understand. So, now I always use enumerate() whenever I need both the item and its position.

Why it is useful:

  1. As you can see, it removes the need of range() and len().
  2. Our code looks more neat and clean.
  3. It’s perfect for debugging as we can see both the index and the value.

2. reversed(): Used to Go Backwards

Previously, when I had to go backward in my list, I used to do like this:

my_list = [1, 2, 3, 4]  
for i in range(len(my_list)-1, -1, -1):  
    print(my_list[i])

I know this is hard and confusing. For me, too. Then I learned about reversed():

for item in reversed(my_list):  
    print(item)

This was much simpler and easier than my previous method. I don’t have to think about indexes or writing long codes.

Why it’s useful:

  1. It’s easier for anyone to understand.
  2. We don’t have to calculate the indexes manually.
  3. It’s perfect if we want to reverse any process like undoing any steps.

[embed]10 Python Features That Seem Confusing (But Are Actually Brilliant) Python features that seem hard but are mind-blowing once you get them. Ready to master the magic? Let’s go!python.plainenglish.io

3. itertools.chain(): Used for Combining Lists

If I have to combine lists previously, I use this method:

list1 = [1, 2]  
list2 = [3, 4]  
combined = list1 + list2  
print(combined)

I know this is an easy and simple method. But, it works perfectly only for small lists, but what if we have many such lists, or large lists that take a lot of memory?

Then…what?

For that we use itertools.chain() :

from itertools import chain  
list1 = [1, 2]  
list2 = [3, 4]  
for item in chain(list1, list2):  
    print(item)

This method doesn’t create a new list. It only combines the list to loop through them.

Why it’s useful:

  1. This method saves the memory, as it doesn’t create a new list.
  2. We can work with as many lists as we want.
  3. It’s perfect if we want to handle large datasets.

4. zip(): Used to match two lists together

I have two list — like this:

names = ['Kiran', 'Ritika', 'Janvi']  
scores = [85, 90, 95]

And I want to pair the name with a score, like this:

  • Kiran: 85
  • Ritika: 90
  • Janvi: 95

For this, I previously used two loops to do this. But now, I only use zip():

for name, score in zip(names, scores):  
    print(f'{name}: {score}')

This method combines two lists, item by item.

Why it’s useful:

  1. It helps us to combine two lists in pairs.
  2. It makes our code look cleaner and more shorter.
  3. It can work with any data type.

5. sorted(): Helps to Sort Anything Quickly

I know, sorting can be very tricky, if we have long loops to sort. I usually write loops if I have to sort any list previously.

Then I learned about this list function, and really it makes my life much easier.

my_list = [3, 1, 4, 2]  
print(sorted(my_list))  # [1, 2, 3, 4]

The above method sorts the list in ascending order. But if we want to sort in reverse order (means in descending order).

Then, we just have to add reverse=True:

print(sorted(my_list, reverse=True))  # [4, 3, 2, 1]

We can even sort the list of dictionaries with this method:

data = [{'name': 'kiran', 'age': 25}, {'name': 'janvi', 'age': 20}]  
print(sorted(data, key=lambda x: x['age']))

Amazing, right?

Why it’s useful:

  1. It helps us to sort in ascending or descending order.
  2. We can easily handle complex data types like dictionaries or objects.

Just try them out and let me tell in the comments, how you feel about them.

If you have any other favorite Python list function, you can share it in the comments. I would love to learn more.😊

Don’t forget to clap, if you like my article.

You may also like:

[embed]I Recently Learned About an Invisible Programming Language Yes, you heard it right. It’s the programming language that you can’t even see.medium.com

[embed]Why Python Lists Are More Powerful Than You Think It’s super important to understand if you are just a beginner in Python.python.plainenglish.io

[embed]Can Mojo Really Replace Python? Let’s Test It A few days ago, I got to know about Mojo on Medium. I just made a pause and read: “Mojo is 35,000 times faster than…medium.com

Thank you for being a part of the community

Before you go:


메타데이터
post_id
6c1bfa8982cf
slug
5-python-list-functions-that-changed-how-i-code-forever-6c1bfa8982cf
url
https://python.plainenglish.io/5-python-list-functions-that-changed-how-i-code-forever-6c1bfa8982cf
canonical_url
https://python.plainenglish.io/5-python-list-functions-that-changed-how-i-code-forever-6c1bfa8982cf
author_url
https://medium.com/@kirantechblog
status
ok
fetched_at
2026-06-28 10:39:35