Python - List Methods & Tasks II

amotbeli

SM

Posted on August 1, 2024

Python - List Methods & Tasks II

Even though I had done the tasks beforehand, watching them being done in class today taught me new things.

I learned that I could use Python's in-built list methods more, instead of falling back to for loop all the time.

For example, I could use the extend method (rather than for loop and append method) to expand a list with the contents of another list. Likewise, I could use the clear method (rather than for loop and remove method) to empty a list.

Unless there is a specific need for using the for loop, like I need to check a condition on individual elements before adding them to or removing them from the list, the code looks much cleaner this way.

💖 💪 🙅 🚩
amotbeli
SM

Posted on August 1, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Python - List Methods & Tasks II
programming Python - List Methods & Tasks II

August 1, 2024

Python - List Methods & Tasks
programming Python - List Methods & Tasks

July 30, 2024

Day 2 - Python Basics
programming Day 2 - Python Basics

July 15, 2024

Hello World
programming Hello World

July 8, 2024