number_names()

Getting to grips with manipulating strings and integers

Keith O’Sullivan
Sep 11, 2019 · 12 min read
Photo by Raphael Schaller on Unsplash

Shifting Perspectives

Photo by Alex Boyd on Unsplash

Approaching number_names()

The first draft of the dictionary, this would remain mostly unchanged
Valient first effort!
This is still unwieldy, but much tidier and I am starting to see my way to a better solution

Clearing away the cobwebs

Photo by David Edkins on Unsplash
I’ve always found the nested dictionary structure more readable than multiple dictionaries
I was quite proud of my use of unpacking here. Pity I had to scrap it pretty quickly though
The check_ functions cover a range of possible variations

Building complexity

Photo by Samuel Zeller on Unsplash
Still relying on strings, identifying negative integers and floating-point values was straightforward
The process of formatting the word strings is now entirely moved to helper functions

Mathematically Speaking

Photo by Roman Mager on Unsplash
The main function is much more simplified now
This iteration simplified the function massively
I was happy to keep this relatively simple
Clean and readable. It was a long journey but I got there
The workhorse of the code. I see a few ways to cut down lines, but I’m not sure it's worth the tradeoffs

Reflections

Photo by Stanislav Kondratiev on Unsplash

inefficient_code():

learning stuff the hard way

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store