Practice Challenge: Find All Names Starting with ‘John’ in a Text File Using Python
Level: Beginner
Learning Python isn’t just about building big apps — it’s about picking up dozens of tiny, practical skills you can use every day.
This is exactly why I share these daily Python projects: so you can train your brain to solve small, real-world problems that pop up in work or life.
Today, you’ll build a program that scans a text file of names and finds every line that starts with a given first name.
It’s a small script, but you’ll learn file handling, string splitting, and filtering — all core Python skills that keep stacking up as you keep practicing.
Project Description
Your task today is to build a small, practical Python app that searches through a text file containing a list of names and surnames, and prints out all the full names that have a specific given name (the first word in each line).
But this time, instead of making your own text file, you’ll use a real dataset provided for you.
It’s a simple .txt
file hosted on Google Drive that looks like this:
Alejandro Morales
John Smith
Hiroshi Tanaka
Ekaterina Ivanova
Luca Bianchi
Amara Diallo
Liam O’Connor
Sofia Petrova
Omar Al-Masri
John Doe
...
So if the user types John
, it will find and display:
These are all the names starting with 'John':
John Smith
John Doe
This is exactly the kind of lightweight program you might write to:
Filter a raw text export from a database,
Quickly look up all records for a given first name,
Or do informal audits of membership or contact lists.
Expected Output
If the name isn’t found:
📁 Getting the data file
Download the provided dataset file here:
Download names.txt from Google Drive
Click the link and download it.
Place it in the same folder as your Python script.
Make sure to name it exactly
names.txt
.
💡 Hint
Not sure how to start? Click the Show Hint button.
It will guide you on how to:
Open and read each line of the file,
Split lines into words to get the first name,
Compare it to the user’s input in a case-insensitive way,
And keep track of all matches in a list to print at the end.
🔍 It also reminds you to .strip()
each line to clean up newlines.
𝌣 Solution
🔒 This solution is available to paid subscribers only.
✅ It includes a clean function that reads the file, checks each first name, and prints all matching full names.
🚀 Want to keep leveling up?
Browse hundreds of projects at dailypythonprojects.substack.com/archive and unlock all solutions by subscribing. Build real Python skills daily and transform how you learn — one project at a time.