Fastest way to detect a non-ASCII character in a list of strings.

Seebs usenet-nospam at seebs.net
Sun Oct 17 18:41:38 EDT 2010


On 2010-10-17, Dun Peal <dunpealer at gmail.com> wrote:
> What's the fastest way to implement `all_ascii(L)`?

Start by defining it.

> 1. Match against a regexp with a character range: `[ -~]`

What about tabs and newlines?  For that matter, what about DEL and
BEL?  Seems to me that the entire 0-127 range are "ASCII characters".
Perhaps you mean "printable"?

> Any other ideas?  Which one do you think will be fastest?

I'd guess that a suitable regex (and see whether there's an
existing character class that already has the right semantics) will
be by far the fastest.  Just anchor it on both ends and nothing will
have to do any fancy evaluation to test it.

-s
-- 
Copyright 2010, all wrongs reversed.  Peter Seebach / usenet-nospam at seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.



More information about the Python-list mailing list