[Tutor] finding sum of digits in a string

dn PythonList at DancesWithMice.info
Tue Mar 15 15:56:33 EDT 2022


On 16/03/2022 03.05, Dennis Lee Bieber wrote:
> On Tue, 15 Mar 2022 15:28:13 +1300, dn <PythonList at DancesWithMice.info>
> declaimed the following:
> 
>> Alternate solution:
>> The spec biases one's thinking by its use of the words: "the ...
>> digits". Instead of that fixation, could we consider something like
>> using translate() to replace any undesired characters with NULSTRING or
>> zero, and then adding the digits/all that remains?
> 
> 	Which leads me to the nightmare I envisioned overnight. Taking common
> phone number formats and stripping down to just digits... While also
> translating those fancy "word-based" phone numbers.
> 
> 	Hadn't realized translate() allows one to "remove" (your NULSTRING)
> case... But that is in the documentation... I'd expected to convert things
> to spaces, split on space, then join on ""
> 
> 
>>>> phone_numbers = [	"+1 (616) 987-5555",
> ... 			"1 (800) CALL-SAM",	#Sam Bernstein law offices
> ... 			"TW7-5555"	]	#old 60s "TWin oaks" exchange


Only too pleased to be able to return the inspirations you have provided
over the years!


This is a great example - for us older folk, eg a vocational context.

Young-people question the use of land-lines, have no knowledge of
rotary-dial phones, and certainly post-date the old system of alpha
exchange-codes. There is?was a very interesting annual 'list'
constructed by an academic in the US (that I can't lay my hands on, at
this moment), which highlights the differences in what 'we' know, and
the 'world-view' of the uni-freshman, eg whether they've ever known a
time before cell-phones, microwave ovens, etc. It's a very useful
reminder that we (presenters) need to adjust our view of 'culture' and
'what is real'. Thus "relevance"!


I've been playing with a 'story' based on a friend with a Japanese
heritage, attempting to help his parents find a new place. He found
somewhere. His sister even 'approved'. However, when he finally took his
parents to view, with a sense of "Ta Da!", before they even stepped out
of the car, he was presented with flat refusal. It turns-out that more
traditional/superstitious folk avoid the number "4" (also in Chinese
culture), which happened to be the number prominently displayed on the
mail-box. Their old (but not as old as me) Mother, saw the portents!

Accordingly, a similar translation/editing/renumbering challenge: some
Japanese buildings proceed from level 3 to level 5, and from level 39
directly to 50. Complicated by source data arriving from various
sources, eg realtors, spreadsheets, web-scraping, etc, and thus some
being strings and some integers. It's a work-in-progress...


The learning-objective is "using the debugger". So, will have syntax
errors in the data, in the code, a calculation error, mistaken choice of
identifier being used, data not being input (probably returned) to/from
a function (which gives us the StepNext and StepInto variation), and
anything else I can think-of/throw-into the 'kitchen sink'...

Thanks!
-- 
Regards,
=dn


More information about the Tutor mailing list