• Home
  • Python
    • Introduction to Python
    • Python Developer
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • React.js
    • Introduction to React
    • React Developer
  • Interactive Training
  • Pricing
  • Brainstorm
STEMTrainingGrounds
  • Courses
    • Home
    • Python
      • Introduction to Python
      • Python Developer
    • JavaScript
      • Introduction to JavaScript
      • JavaScript Developer
    • React
      • Introduction to React
      • React Developer
  • Interactive Training
  • Pricing
  • Brainstorm

Quick Links

  • About Us
  • Pricing
  • Partnership
  • Brainstorm
  • Terms
  • Privacy
  • Refunds

Courses

  • Python
    • Introduction to Python
    • Python Developer
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • React
    • Introduction to React
    • React Developer

Newsletter

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

© 2025 - 2026 STEMTrainingGrounds. All Rights Reserved.

Python Developer - Lesson 10

Lesson 10 of 34

List processing

Lesson Progress: 0%

Lesson Progress: 0%
List processing
Lesson Incomplete
← Previous: Interactive REPL
Lesson 10 of 34
Next: Exception Handling →
Code Example
fruits = ["apple", "banana"]
fruits.append("cherry")
print(fruits)

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

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

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
colors = ["red", "blue"]
more_colors = ["green", "yellow"]
colors.extend(more_colors)
print(colors)

points = [10, 20]
points.extend([30, 40])
print(points)

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

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
names = ["Alice", "Charlie"]
names.insert(1, "Bob")  # Puts "Bob" at index 1
print(names)

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

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

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
pets = ["cat", "dog", "bird"]
pets.remove("dog")
print(pets)

scores = [10, 50, 100]
scores.remove(50)
print(scores)

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

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
letters = ["a", "b", "c"]
last_item = letters.pop()  # Removes "c"
print(letters)
print(last_item)

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

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

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
prices = [5.0, 1.0, 3.5]
prices.sort()
print(prices)

kids = ["Zane", "Abby", "Mark"]
kids.sort()
print(kids)

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • The sort() function helps put items in order in a list.
  • It is used with lists to organize the items inside them.
  • Numbers are sorted from smallest to biggest (this is called ascending).
  • Words are sorted in alphabetical order, like a dictionary.
Code Example
countdown = [1, 2, 3]
countdown.reverse()
print(countdown)

words = ["world", "hello"]
words.reverse()  
print(words)

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • The reverse() function flips the order of items in a list.
  • It works on lists and changes the order of the items inside them.
  • Ascending means going from smallest to biggest or A to Z.
  • Descending means going from biggest to smallest or Z to A, which is what reversing can help show.
Code Example
players = ["Sam", "Jan", "Kit"]
total = len(players) 
print(total)

items = [10, 20, 30, 40, 50]
count = len(items)  
print(count)

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • The len() function tells you how many items are in a list.
  • It counts each item in the list one by one to give a total.
  • Even though counting starts at 1, list positions (indexes) start at 0.
  • So the first item is at position 0, but it is still counted as one item.
Code Example
# Everyone finished the race
finished = [True, True, True]
result = all(finished)  # result is True
print(result)

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

# 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:

Editor Output:

Click "Run Code" to see the output here
  • The all() function checks if every item in a list is true.
  • If all items are true, it returns True, but if even one is false, it returns False.
  • It looks at each item one by one to make sure they all pass the check.
  • This is similar to using "and" in logic, which you will learn more about later.
Code Example
# Someone found the hidden key
found_key = [False, True, False]
result = any(found_key) # result is True
print(result)

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

# 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:

Editor Output:

Click "Run Code" to see the output here
  • The any() function checks if at least one item in a list is true.
  • If one or more items are true, it returns True, otherwise it returns False.
  • It looks through the list until it finds something that is true.
  • This is similar to using "or" in logic, which you will learn more about 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:

Editor Output:

Click "Run Code" to see the output here
  • The all() function can check rules, not just simple true or false values.
  • (n > 2 for n in numbers) checks each number to see if it is bigger than 2.
  • (len(w) >= 3 for w in words) checks if each word has at least 3 letters.
  • (user["active"] for user in users) checks if each user is active.
  • All checks must be true for all() to return True.
Code Example
# Check if any number is greater than 10
numbers = [3, 5, 12]
result = any(n > 10 for n in numbers)
print(result)  # This will be True


# Check if any word has at least 5 letters
words = ["cat", "dog", "elephant"]
result = any(len(w) >= 5 for w in words)
print(result)  # This will be True


# Check if any user is active
users = [
    {"name": "David", "active": False},
    {"name": "Mike", "active": True}
]
result = any(user["active"] for user in users)
print(result)  # This will be True

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • The any() function checks if at least one item in a list meets a condition.
  • Instead of just True or False values, you can give any() a rule to check, like n > 10.
  • The part (n > 10 for n in numbers) checks each number to see if it is greater than 10.
  • The part (len(w) >= 5 for w in words) checks if any word has 5 or more letters.
  • The part (user["active"] for user in users) checks if any user is active.
  • If even one check is true, any() will return True.

Test Incomplete

What is a list in Python best compared to?

Question #

1/15

Score

0/0 - 0.0 %