The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

Mark Lawrence breamoreboy at yahoo.co.uk
Sun Mar 20 21:28:26 EDT 2016


On 21/03/2016 01:15, BartC wrote:
> On 15/03/2016 00:25, BartC wrote:
>  > On 14/03/2016 23:24, Steven D'Aprano wrote:
>
>  >> Try this instead:
>  >>
>  >> c = chr(c)
>  >> if 'A' <= c <= 'Z':
>  >>      upper += 1
>  >> elif 'a' <= c <= 'z':
>  >>      lower += 1
>  >> elif '0' <= c <= '9':
>  >>      digits += 1
>  >> else:
>  >>      other += 1
>  >>
>  >> But even better:
>  >>
>  >> if c.isupper():
>  >>      upper += 1
>  >> elif c islower():
>  >>      lower += 1
>  >> elif c.isdigit():
>  >>      digits += 1
>  >> else:
>  >>      other += 1
>  >>
>  >> which will work correctly for non-ASCII characters as well.
>  >
>  > Yes, but now you've destroyed my example!
>  >
>  > A more realistic use of switch is shown below [not Python].
>
> A tokeniser along those lines in Python, with most of the bits filled
> in, is here:
>
> http://pastebin.com/dtM8WnFZ
>

I got to line 22, saw the bare except, and promptly gave up.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence




More information about the Python-list mailing list