
Python practice
Python list and array practice questions
15 problems, ordered from easiest. They run in your browser, and 15 are free.
Start with Collapse Consecutive DuplicatesThe idea in a minute
A list holds values in order. Most array problems come down to walking through it, keeping a running answer, and handling the edge cases such as an empty list.
The problems begin with sums and maximums and move on to reversing, rotating and merging.
Example: Running total and maximum
nums = [4, 9, 2, 7]
total = 0
best = nums[0]
for n in nums:
total += n
best = max(best, n)
print(total, best, nums[::-1])What it prints
22 9 [7, 2, 9, 4]What to watch for
- An empty list is the edge case that most solutions forget.
- Copying a list with b = a does not copy it. Use a.copy() or a[:].
- Negative indexes count from the end, so a[-1] is the last item.
Arrays problems
- Collapse Consecutive Duplicatesbeginner · Free
- Remove Duplicates Preserving Orderbeginner · Free
- Find Missing Numberbeginner · Free
- Product Except Selfbeginner · Free
- Best Time Buy Sellbeginner · Free
- Find All Duplicatesbeginner · Free
- Find Disappearedbeginner · Free
- Find Duplicate Numberbeginner · Free
- Forward-fill Nonebeginner · Free
- Smallest number from odd digitsbeginner · Free
- Negatives before non-negativesbeginner · Free
- Split records into batchesbeginner · Free
- Skip tasks that already ranbeginner · Free
- Wait times for retriesbeginner · Free
- Load only the new rowsbeginner · Free
Want a guided order across every topic? Open the practice sheets or the Python hub.