Promptar Lead | Python Trainer

#standard-library Articles


A Python Journey on Counting: Refinements

In the first installment of this journey we created progressively simple versions of a letter histogram creation function, as a motivation to introduce useful built-in and Standard Library Tools, while sharing general ideas about code simplification. The resulting code was short and fast, meeting all initial requirements. But it should be better. In this article I’ll explore further refinements to our solution, raising the bar on the requirements: this will steer us into the exploration of topics like Unicode text processing and API design — both tangential to the letter-counting problem, but otherwise with a very wide reach, on their own.

A Python Journey on Counting: Foundation

Counting things is an apparently trivial computational problem. In this article series — more of a journey than a short single-topic read — I’ll go over the process of producing a letter-based histogram from a piece of text, as a motive to progressively introduce several useful built-in and Standard Library tools. Along the way I’ll share a few tips and thoughts on coding principles, related topics, like unicode text processing, and, for completeness, ideas on possible output production. The key takeaway is that Python has many built-in and Standard Library tools that, used in the right combination, lead to simpler, shorter code, that being correct and easier to understand and manage, will also be faster.