You can use a for loop to easily go through every item in a list:
python
items = ['a', 'b', 'c']for item in items: print(item)
Output
a
b
c
Your output
Common Misconceptions
List indices start at 1.
Python lists are zero-indexed, meaning the first element is at index 0.
You cannot change a list once it is created.
Lists are mutable. You can change their elements, add new ones, or remove them.
append() can add multiple items at once.
append() takes exactly one argument and adds it as a single element to the end. To add multiple elements from an iterable, use extend().
Edge Cases
Empty lists [] are completely valid and have a length of 0.
Appending a list to a list (e.g., a.append([1, 2])) adds the list as a single nested element, rather than flattening it.
Under the Hood
Watch how list modification and appending works in memory step-by-step:
Array or Linked List? Score the Workload, Not the Table โ Everyone memorises the table - arrays index fast, linked lists insert fast - and still cannot pick one. Run both structures against the same operations here and watch the totals swap places depending only on what the code actually does.
Appending Is O(1) on Average, and the Average Hides the Interesting Part โ Most appends to a list write one slot. Occasionally one copies the entire array. Change the growth strategy here and watch the spikes move - growing by a fixed amount stays quadratic however large the amount is.
Stacks and Queues, Shown Doing the Jobs They Exist For โ Knowing that a stack is last-in-first-out explains nothing about why anyone wanted one. Here a stack matches brackets and catches the error a counter would miss, and a queue runs a ring buffer whose values never move at all.
More Buckets Will Not Save a Bad Hash Function โ Hash tables are called O(1) so often that the condition gets dropped. Change the hash function here, drag the table from 4 buckets to 16, and watch the longest chain refuse to move - because memory cannot fix a hash that ignores its input.
Why Databases Use B-Trees: Fewer Levels Beats Fewer Comparisons โ A balanced binary tree of a billion keys is thirty levels deep. If every level is a disk read, that is thirty reads for one lookup. Drag the branching factor here and watch the same keys collapse from a tall thin tree into a short wide one.
A Heap Is a Tree You Can Store in a Flat Array โ Heaps are taught as trees and implemented as arrays, and the join between the two is usually three index formulas nobody explains. Watch a value sift up and down here, moving in the tree and the array at the same time, one swap per click.
In a Trie, Lookup Cost Depends on the Word, Not on How Many Words โ A trie stores words letter by letter, sharing every common prefix. Walk one here by clicking letters, and watch the reachable set shrink - that walk is exactly what an autocomplete box does while you type.
100% Accurate and Useless: Pick a Model Before You See Its Score โ Nobody overfits on purpose. They overfit because the number in front of them is going up. Tune a classifier on training data here, commit to it, and only then find out what it scores on data it has never seen.
Breadth-First and Depth-First Are the Same Loop, One Line Apart โ BFS and DFS get taught as two algorithms because one is usually written with a queue and the other with recursion. Run both here from one shared loop, changing only which end of the frontier the next node comes from, and watch the paths diverge.
List or Matrix? Guess Before You Look, and Watch the Answer Flip โ Lists for sparse graphs, matrices for dense ones is true enough to repeat and too vague to use. Predict the winner here on two dials - density and question mix - and find out how often the rule of thumb is wrong.
Your Prompt Has 3,840 Right Answers, and It Picked One โ Write a post about our launch is six words and not a request for one thing. Count the decisions it leaves open and the options multiply out to 3,840 different replies, every one of them a fair reading. Send it here, watch the model fill in your blanks, and see what specifying actually buys.
Union-Find Has Two Optimisations Because It Has Two Different Failures โ Union by size and path compression are usually presented as one improvement after another. They rescue unrelated cases - and each is useless against the other's. Toggle them independently here and watch which merge order defeats which.
Play the Cache: Why LRU Sometimes Scores Zero โ A cache has to decide what to throw away before it knows what will be asked for next. Take the eviction decision yourself here, scored live against LRU and against the best any policy could possibly do.
No Sorting Algorithm Wins. Look at Your Data First. โ Insertion sort is not slow and quicksort is not fast - each is the cheapest choice for some shape of input and the dearest for another. Predict the winner across five shapes here and watch a single favourite fail.