shorten this: if char in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz":

Nick Craig-Wood nick at craig-wood.com
Wed Jun 25 10:32:17 CEST 2008


Guilherme Polo <ggpolo at gmail.com> wrote:
>  Let me post another one, and longer:
> 
>  if ord(somechar) in range(ord('A'), ord('Z') + 1) + range(ord('a'),
>  ord('z') + 1):
>      ...

That is very inefficient!  Every time it is run it creates two lists
then joins them then throws the whole lot away!

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list