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

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to