A Python Question That Took Me Days To Solve When I Just Started

Liu Zuo Lin
CodeX
Published in
5 min readDec 3, 2021

--

4 years ago in mid 2017, I took my first basic Python class in University. This class titled introduction to programming introduced us to programming in Python, and occasionally threw us a couple of curveball questions (both during practices & examinations) in order to force us to learn to think like a programmer (and to segregate the A+ students from the rest).

I remember spending days on one such question, and would think that this would be worthwhile to share it here for those of you who might still be learning the fundamentals of programming. Here it is!

Splitting PascalCase Strings Into Words

PascalCasing is a naming convention that involves joining different words together without spacing & capitalising the first letter of each word. Here are some examples:

strings = [
"HelloWorld",
"ILikeApples",
"HelloImBobAndIm30",
"300DogsAnd300Cats"
]

Our task was to write a function the separate each PascalCase string into a list of its component words:

"HelloWorld" -> ["Hello", "World"]
"ILikeApples" -> ["I", "Like", "Apples"]
"HelloIAmBobAndIAm30" -> ["Hello", "Im", "Bob", "And", "Im", "30"]
"300DogsAnd300Cats" -> ["300", "Dogs", "And", "300", "Cats"]

--

--