STR Coding Club logo STR Coding ClubLearn to code, together
Python and Practice

Python List Practice With Six Exercises for Beginners

You can write a list in Python, you know square brackets hold items, and yet the moment a task says "keep only the even scores" or "find the second largest" your mind goes blank. That is normal.

Students at a coding club working through Python list exercises on laptops

You can write a list in Python, you know square brackets hold items, and yet the moment a task says "keep only the even scores" or "find the second largest" your mind goes blank. That is normal. Python list practice works best with short problems that each force one specific skill, not with a long tutorial you read once and forget.

These six exercises are the ones I run with new members in our Thursday club sessions. Each takes between 10 and 25 minutes, and together they cover almost every list move a beginner needs for their first real program.

Before You Start Python List Practice

Open a plain .py file rather than typing into the interactive prompt. You want to be able to rerun the whole thing after every change. Keep a second file called notes.py where you paste any line that surprised you, with a comment explaining why.

A quick refresher on the four operations you will use constantly:

  • Indexing: scores[0] is the first item, scores[-1] is the last.
  • Slicing: scores[1:4] gives items at positions 1, 2 and 3, never 4.
  • Adding: scores.append(12) adds to the end, scores.insert(0, 12) adds to the front.
  • Removing: scores.pop() removes and returns the last item, scores.remove(12) removes the first 12 it finds.

If you are still getting used to running files at all, our guide on practising Python with small exercises explains a routine that keeps sessions short and steady.

Six Exercises, From Warm Up to Stretch

1. The shopping list editor (10 minutes)

Start with items = ["milk", "bread", "eggs"]. Write code that adds "apples" to the end, puts "coffee" at the front, removes "bread", and prints the final list and its length. Expected output: ['coffee', 'milk', 'eggs', 'apples'] and 4. The point is to feel the difference between append, insert and remove without thinking about loops yet.

2. Even scores only (15 minutes)

Given scores = [7, 12, 3, 18, 9, 22, 14], build a new list containing only the even numbers. Do it first with a for loop and an if statement. Only after that works, try the one line version with a list comprehension. Writing both teaches you what the short version is actually doing.

3. Second largest without sorting (20 minutes)

Find the second largest number in [41, 17, 88, 63, 88, 5] without calling sort or sorted. Watch out for the duplicate 88: the answer should be 63, not 88. This one trips up almost everyone the first time, which is exactly why it is on the list. Track two variables, largest and second, and update them carefully inside one loop.

4. Rotate a playlist (15 minutes)

Take songs = ["A", "B", "C", "D", "E"] and write a function rotate(songs, n) that moves the first n songs to the end. rotate(songs, 2) should return ["C", "D", "E", "A", "B"]. Slicing solves it in one line. Then ask yourself what should happen when n is 7, and fix it with the modulo operator.

5. Remove duplicates but keep order (20 minutes)

Turn ["red", "blue", "red", "green", "blue", "yellow"] into ["red", "blue", "green", "yellow"]. Converting to a set removes duplicates but can scramble the order, so build a new list and only append items you have not seen yet. Bonus: once you have done our Python dictionary practice exercises, try counting how many times each colour appeared.

6. Club attendance tracker (25 minutes)

The stretch task. You have a list of lists, one per week: [["Ana", "Ben"], ["Ana", "Cleo", "Ben"], ["Cleo"], ["Ana", "Ben", "Cleo", "Dev"]]. Print each person's name with the number of weeks they attended, sorted from most to least. This combines nested loops, building a new list and sorting by a key. When you want to keep the data between runs, the next step is saving it to a file, which our Python file handling practice walks through.

Common Mistakes Each Exercise Exposes

MistakeWhere it shows upWhat to remember
Changing a list while looping over itExercise 2, if you remove odd numbers in placeBuild a new list instead
Off by one in slicesExercise 4The end index is never included
Assuming sort returns a listExercise 6list.sort() returns None; sorted() returns a new list
Copying with = instead of .copy()Any exercise that edits a listb = a makes two names for one list

The last one causes more confused messages in our club chat than any other. If you write backup = scores and then change scores, backup changes too, because both names point at the same list in memory.

Why You Should Not Rush to List Comprehensions

A lot of tutorials push list comprehensions in the first week because they look clever and Pythonic. I think that is backwards for most beginners. A comprehension squeezes a loop, a condition and an append into one line, and when it gives the wrong answer a new coder has no idea which of the three parts failed.

In our club we have a rule: you may only write a comprehension for a task you have already solved with a normal loop. Members who follow it debug their own code noticeably faster by the second month, because they can mentally unfold the short version into steps. The one liners come naturally after about three or four weeks of regular practice, and by then they actually understand them.

How to Keep Practising After These Six

Repeat any exercise you needed help with after two days, from a blank file, without looking at your old answer. If you can solve it cold in under half the original time, move on. If not, it goes back in the queue.

Then make your own variations. Swap numbers for words, change "even" to "longer than five letters", or combine exercises 3 and 5. Twenty minutes, three or four times a week, beats a single three hour weekend session every time.

If you practise with a friend, swap problems. Write one list exercise each, with the expected output, and solve the other person's. Writing a good exercise is surprisingly hard, and it teaches you to think about edge cases like empty lists, a single item, or every value being the same. Those three cases catch more bugs in beginner code than anything else.

FAQ

How many list exercises should a beginner do?

Around 15 to 20 varied problems is usually enough to feel comfortable. The variety matters more than the count, so make sure you cover adding, removing, slicing, searching and sorting.

What is the difference between a list and a tuple in Python?

A list can be changed after you create it, while a tuple cannot. Use lists for collections that grow or shrink, such as attendance, and tuples for fixed groups like a pair of coordinates.

Should I learn lists or dictionaries first?

Lists first. They are simpler, they appear in almost every beginner program, and dictionaries make more sense once you have felt the pain of searching through a list by position.

Why does my list print None after sorting?

You probably wrote result = scores.sort(). The sort method changes the list in place and returns None. Either call scores.sort() on its own line or use result = sorted(scores).

SD
Selene Dragomir

Selene coaches students for programming contests. She writes about practice problems, debugging and the habits that help beginners get unstuck on their own.

More posts by Selene

More in Python and Practice

01doorganico 084goad 3hot8 4465456 after5internprogram ahandfulofblessings ahmadpc ahomcybersecurity allodialresources annodex antiquesandperiodcollectibles aotc asianworldkashmir beedlectrics bloggertemplatefree bluefeatheragency bodyweightsolution campaign08blog carfixadvisor catstreetcollective cbstvsports cnfanspurchasing committeeof500yearsofdignityandresistance covertopsdjs cs-kaiyuangame cuestacomunicaciontotal cxoutlet dancebetgame deskgearhub destinyvillastay detectmagazine di33 diamondsteelbuildings donmo dyanadropship emarsysfinance emimattl escapechan eskitarih evautoplay everythingweddings-orlando farmzone feedviewerapp foxstudiosscratch gamevui123 gleasongrade greetingsday hacklabasu haskell iw-kaiyun jagoanproperti jilidskripsi joltbusinessfinance juegodepokergratis juegospucca kaeru-festival latestmehndidesigns lestanzediottaviano litemagazines localcommunityhero lustrsazan mariashebets menswheels newwebstechs1 nikkit ootheday oxigenvpn plurfitness prefetial probudgetcarpetcleaning psychicmrsmartin pyaten qvantor rejoignezlogis rexzbot riselayouts ruchin rwxqsgd5 sakaltime shibiaowang shop-bot skrtips spotlesshaven tetapatrium topselller uneplanteartificielle vipertechcr webtech1223411 wo-kygaming yamaha-mekar yeknava yoybuysheets zenunwa yamaha-mekar jilidskripsi ankertoto ankertoto ankertoto