• Home
  • Python
    • Introduction to Python
    • Python Developer
    • Expert Python Developer
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
    • Expert JavaScript Developer
  • React.js
    • Introduction to React
    • React Developer
    • Expert React Developer
  • Linux
    • CyberSecurity - Introduction to Linux
    • CyberSecurity - Linux Administrator
    • CyberSecurity - Expert Linux Administrator
  • Active Directory
    • CyberSecurity - Introduction to Active Directory
    • CyberSecurity - Active Directory Administrator
    • CyberSecurity - Expert Active Directory Administrator
  • Interactive Training
  • Pricing
  • Brainstorm
STEMTrainingGrounds
  • Courses
    • Home
    • Python
      • Introduction to Python
      • Python Developer
      • Expert Python Developer
    • JavaScript
      • Introduction to JavaScript
      • JavaScript Developer
      • Expert JavaScript Developer
    • React
      • Introduction to React
      • React Developer
      • Expert React Developer
    • Linux
      • CyberSecurity - Introduction to Linux
      • CyberSecurity - Linux Administrator
      • CyberSecurity - Expert Linux Administrator
    • Active Directory
      • CyberSecurity - Introduction to Active Directory
      • CyberSecurity - Active Directory Administrator
      • CyberSecurity - Expert Active Directory Administrator
  • Interactive Training
  • Pricing
  • Brainstorm

Quick Links

  • About Us
  • Pricing
  • Brainstorm

Courses

  • Python
    • Introduction to Python
    • Python Developer
    • Expert Python Developer
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
    • Expert JavaScript Developer
  • React
    • Introduction to React
    • React Developer
    • Expert React Developer
    • Professional Master React Developer
  • Linux
    • CyberSecurity - Introduction to Linux
    • CyberSecurity - Linux Administrator
    • CyberSecurity - Expert Linux Administrator
  • Active Directory
    • CyberSecurity - Introduction to Active Directory
    • CyberSecurity - Active Directory Administrator
    • CyberSecurity - Expert Active Directory Administrator

Newsletter

Subscribe to our monthly newsletter, for a quick update on Python, JavaScript, React news

© 2024 - 2026 STEMTrainingGrounds. All Rights Reserved.

Lesson 10

Lesson 10 of 34

List processing

Lesson Progress: 0%

Code Example

# Example 1
fruits = ["apple", "banana"]
fruits.append("cherry")

# Example 2
numbers = [1, 2, 3]
numbers.append(4)

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • A list is like a backpack where you can keep many different items together.
  • If you want to add something new to the end of your list, you use the append() helper.
  • Just tell Python which list you are using, then add the new item inside the parentheses.
  • For example, fruits.append("cherry") puts a cherry at the very end of your fruit list.

Code Example

# Example 1
colors = ["red", "blue"]
more_colors = ["green", "yellow"]
colors.extend(more_colors)

# Example 2
points = [10, 20]
points.extend([30, 40])

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • Sometimes you have two different lists and you want to join them together into one big list.
  • Python has a helper called extend() that lets you pour one list into another.
  • It doesn't just add one item; it adds every single item from the second list to the end of the first one.
  • It's like taking two boxes of toys and dumping the smaller box into the bigger one to keep them all together.

Code Example

# Example 1
names = ["Alice", "Charlie"]
names.insert(1, "Bob")  # Puts "Bob" at index 1

# Example 2
queue = [2, 3, 4]
queue.insert(0, 1)      # Puts 1 at the very start

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • While append() always goes to the end, insert() lets you pick any spot in your list.
  • You just need to tell Python two things: the "spot number" and the item you want to put there.
  • Remember that Python starts counting its spots at 0, so the first spot is actually number 0!
  • It's like cutting in line—everyone else simply moves over to make room for the new arrival.

Code Example

# Example 1
pets = ["cat", "dog", "bird"]
pets.remove("dog")

# Example 2
scores = [10, 50, 100]
scores.remove(50)

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • If you have something in your list that you don't want anymore, you can use remove().
  • You just need to put the name of the item you want to get rid of inside the parentheses.
  • Python will look through your list, find that specific item, and take it out for you.
  • It's like using an eraser to rub out one specific word from a sentence you wrote.

Code Example

# Example 1
letters = ["a", "b", "c"]
last_item = letters.pop()  # Removes "c"

# Example 2
tasks = ["clean", "cook", "sleep"]
first_task = tasks.pop(0)  # Removes "clean"

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • The pop() helper is like a "grabber" that takes an item out of your list so you can use it.
  • If you leave the parentheses empty, Python will automatically grab the very last item in the list.
  • You can also give it a spot number, like 0, to grab a specific item from that position instead.
  • Once an item is "popped," it is gone from the list, but you can save it into a variable to use later!

Code Example

# Example 1
prices = [5.0, 1.0, 3.5]
prices.sort()

# Example 2
kids = ["Zane", "Abby", "Mark"]
kids.sort()

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • The pop() helper is like a "grabber" that takes an item out of your list so you can use it.
  • If you leave the parentheses empty, Python will automatically grab the very last item in the list.
  • You can also give it a spot number, like 0, to grab a specific item from that position instead.
  • Once an item is "popped," it is gone from the list, but you can save it into a variable to use later!

Code Example

# Example 1
countdown = [1, 2, 3]
countdown.reverse()  # Becomes [3, 2, 1]

# Example 2
words = ["world", "hello"]
words.reverse()      # Becomes ["hello", "world"]

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • The pop() helper is like a "grabber" that takes an item out of your list so you can use it.
  • If you leave the parentheses empty, Python will automatically grab the very last item in the list.
  • You can also give it a spot number, like 0, to grab a specific item from that position instead.
  • Once an item is "popped," it is gone from the list, but you can save it into a variable to use later!

Code Example

# Example 1
players = ["Sam", "Jan", "Kit"]
total = len(players)  # total is 3

# Example 2
items = [10, 20, 30, 40, 50]
count = len(items)    # count is 5

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • The pop() helper is like a "grabber" that takes an item out of your list so you can use it.
  • If you leave the parentheses empty, Python will automatically grab the very last item in the list.
  • You can also give it a spot number, like 0, to grab a specific item from that position instead.
  • Once an item is "popped," it is gone from the list, but you can save it into a variable to use later!

Code Example

# Example 1: Everyone finished the race
finished = [True, True, True]
result = all(finished)  # result is True
print(result)

# Example 2: One person forgot their shoes
has_shoes = [True, False, True]
result = all(has_shoes) # result is False
print(result)

# Example 3: Checking if all numbers are non-zero
numbers = [1, 5, 10]
result = all(numbers)   # result is True
print(result)

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • The pop() helper is like a "grabber" that takes an item out of your list so you can use it.
  • If you leave the parentheses empty, Python will automatically grab the very last item in the list.
  • You can also give it a spot number, like 0, to grab a specific item from that position instead.
  • Once an item is "popped," it is gone from the list, but you can save it into a variable to use later!

Code Example

# Example 1: Someone found the hidden key
found_key = [False, True, False]
result = any(found_key) # result is True
print(result)

# Example 2: Nobody is awake
is_awake = [False, False, False]
result = any(is_awake)  # result is False
print(result)

# Example 3: At least one person has a snack
has_snack = [False, False, True]
result = any(has_snack) # result is True
print(result)

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • The pop() helper is like a "grabber" that takes an item out of your list so you can use it.
  • If you leave the parentheses empty, Python will automatically grab the very last item in the list.
  • You can also give it a spot number, like 0, to grab a specific item from that position instead.
  • Once an item is "popped," it is gone from the list, but you can save it into a variable to use later!

Code Example

# Check if all numbers are greater than 2
numbers = [3, 5, 10]
result = all(n > 2 for n in numbers)
print(result)
)

# Check if all words have at least 3 letters
words = ["cat", "dog", "bear"]
result = all(len(w) >= 3 for w in words)
print(result)  # This will be True

# Check if all words have at least 3 letters
users = [{"name": "David","active": True},
{"name": "Mike","active": True}]
result = all(user["active"] for user in users)
print(result)

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • The pop() helper is like a "grabber" that takes an item out of your list so you can use it.
  • If you leave the parentheses empty, Python will automatically grab the very last item in the list.
  • You can also give it a spot number, like 0, to grab a specific item from that position instead.
  • Once an item is "popped," it is gone from the list, but you can save it into a variable to use later!
Lesson Progress: 0%
List processing
Lesson Incomplete
← Previous: Interactive REPL
Lesson 10 of 34
Next: Exception Handling →