Ojasa Mirai

Ojasa Mirai

Python

Loading...

Learning Level

🟢 Beginner🔵 Advanced
🎯 Why Data Structures Matter📋 Lists: Ordered Collections🔑 Dictionaries: Key-Value Pairs🎪 Sets: Unique Values & Speed📦 Tuples: Immutable Sequences⚖️ Comparing All Data Structures🔧 Mastering List Methods⚡ Advanced Dictionary Patterns🔄 Power of Set Operations🏗️ Building Nested Structures⚙️ Performance Tuning & Optimization
Python/Data Structures/List Methods Operations

🔧 List Methods and Operations — Manipulating Collections

Lists come with powerful built-in methods to add, remove, and modify items.


🎯 Adding Items to Lists

`append()` adds an item to the end of a list.

tasks = ["read", "code"]
tasks.append("exercise")
print(tasks)  # ['read', 'code', 'exercise']

`insert()` adds an item at a specific position.

tasks = ["read", "code", "sleep"]
tasks.insert(1, "exercise")  # Insert at index 1
print(tasks)  # ['read', 'exercise', 'code', 'sleep']

💡 Removing Items

`remove()` deletes the first occurrence of a value.

tasks = ["read", "code", "code", "sleep"]
tasks.remove("code")
print(tasks)  # ['read', 'code', 'sleep']

`pop()` removes and returns an item at a specific index (default: last item).

tasks = ["read", "code", "sleep"]
last_task = tasks.pop()     # Remove last: 'sleep'
first_task = tasks.pop(0)   # Remove first: 'read'
print(tasks)  # ['code']

🎨 Real-World Example: Shopping List

# Start with a shopping list
shopping = ["milk", "bread", "eggs"]

# Add items
shopping.append("butter")
shopping.insert(1, "cheese")

# Remove items (forgot to buy milk)
shopping.remove("milk")

print(shopping)  # ['cheese', 'bread', 'eggs', 'butter']

📊 Common List Methods

MethodPurposeExample
`append(x)`Add to end`list.append(5)`
`insert(i, x)`Add at index`list.insert(0, 5)`
`remove(x)`Remove value`list.remove(5)`
`pop(i)`Remove & return item`item = list.pop()`
`clear()`Remove all items`list.clear()`
`sort()`Sort in place`list.sort()`
`reverse()`Reverse in place`list.reverse()`

🔑 Key Takeaways

  • ✅ `append()` adds items to the end
  • ✅ `insert()` adds items at specific positions
  • ✅ `remove()` deletes by value, `pop()` deletes by index
  • ✅ Lists are **mutable**—you can change them after creation

Ready to practice? Challenges | Quiz


Resources

Python Docs

Ojasa Mirai

Master AI-powered development skills through structured learning, real projects, and verified credentials. Whether you're upskilling your team or launching your career, we deliver the skills companies actually need.

Learn Deep • Build Real • Verify Skills • Launch Forward

Courses

PythonFastapiReactJSCloud

© 2026 Ojasa Mirai. All rights reserved.

TwitterGitHubLinkedIn