Skip to main content
March 23, 2026Brian McClain/2 min read

Python Programming Challenge #3 - Converting File Names to Headlines

Master Python String Manipulation Through Practical File Processing

Programming Challenge Overview

This challenge demonstrates core Python string manipulation techniques by converting file names into properly formatted headlines through systematic text processing.

Key Programming Concepts Covered

String Methods

Seven different string methods are utilized in this solution. These methods handle text transformation, replacement, and formatting operations essential for file name processing.

List Processing

One list method is employed alongside string operations. The combination demonstrates how to work with collections while performing text manipulations.

Conditional Logic

Multiple conditional checks handle junk words, capitalization rules, and file extensions. This logic ensures proper headline formatting according to specified requirements.

Video Transcription

The challenge presented here is deceptively straightforward: create a function that transforms raw file names into properly formatted headlines. This function must accept a list of file names—whether hyphenated, unhyphenated, with or without extensions—and return clean headlines where words maintain their original sequence, capitalization follows standard headline rules (excluding predetermined "junk words"), hyphens become spaces, and file extensions disappear entirely.

Our implementation begins with the make_headlines function, which accepts a list of files as its parameter. The foundation of our approach involves creating an empty list to house our processed headlines, then systematically transforming each filename. We start by replacing hyphens with spaces and converting the entire filename to lowercase—this normalization step ensures consistent processing regardless of the original formatting inconsistencies that plague real-world file systems.

The capitalization logic requires particular attention to headline conventions. The opening word must always be capitalized, even when it appears in our junk word list—this adherence to standard editorial practices ensures professional output. As we iterate through each word, we apply conditional capitalization: words not found in the junk word list receive title case treatment, while common articles, prepositions, and conjunctions remain lowercase (unless they occupy the crucial first position).

The headline construction process involves a secondary loop through our word list, building the final string while applying our capitalization rules. This two-pass approach—first for rule determination, second for string assembly—provides clarity and maintainability that single-pass solutions often sacrifice. During construction, we carefully handle spacing and ensure that junk words beginning phrases don't disrupt our capitalization logic for subsequent meaningful terms.

File extension handling represents the final critical step in our transformation pipeline. When a dot appears in our processed string, we employ string slicing to capture everything preceding the extension marker, effectively stripping away file type indicators that have no place in professional headlines. For files without extensions, we preserve the entire processed string while removing any trailing whitespace that could compromise formatting consistency. The function concludes by returning our curated list of headlines, ready for implementation in content management systems, automated publishing workflows, or any application requiring clean, properly formatted titles from messy filename inputs.

Function Implementation Process

1

Initialize Function Structure

Define the make_headlines function with a files list parameter and create an empty list to store the processed headlines.

2

Text Preprocessing

Replace hyphens with spaces, convert file names to lowercase, and create a word list from the processed string.

3

Apply Capitalization Rules

Ensure the first word is always capitalized, then loop through remaining words to capitalize only non-junk words.

4

Build Headlines

Construct the final headline string by processing each word according to capitalization rules and joining with spaces.

5

Handle File Extensions

Check for dots in the processed text and remove file extensions by slicing the string appropriately before adding to results.

Solution Metrics

16
lines of code in current solution
7
string methods utilized
1
list method employed

Current Solution Analysis

Pros
Handles multiple file name formats including hyphenated and extension variations
Properly manages junk word filtering while maintaining word order
Ensures first word capitalization regardless of junk word status
Successfully removes file extensions through dot detection
Uses standard Python string and list methods for broad compatibility
Cons
Current implementation is 16 lines and could be more concise
Solution lacks flexibility for different formatting requirements
Hard-coded logic limits adaptability to varying use cases
No error handling for edge cases or malformed input

Implementation Requirements Verification

0/5
Refactoring Opportunity

The current 16-line solution can be refactored to improve flexibility and maintainability, allowing for easier adaptation to different headline formatting requirements.

Key Takeaways

1Python string methods provide powerful tools for text transformation, with seven different methods utilized in this file processing solution
2Proper algorithm design requires handling multiple input formats including hyphenated names and files with or without extensions
3Conditional logic is essential for implementing business rules like junk word filtering while maintaining proper capitalization
4List and string method combinations enable complex text processing workflows for practical file management tasks
5The current 16-line implementation demonstrates functional programming but offers opportunities for refactoring to improve flexibility
6File extension removal requires careful string slicing based on dot detection to avoid corrupting the processed text
7First word capitalization rules must override junk word filtering to maintain proper headline formatting standards
8Code refactoring can improve solution maintainability while preserving core functionality and processing requirements

RELATED ARTICLES