Fastest way to detect a non-ASCII character in a list of strings.
Dun Peal
dunpealer at gmail.com
Sun Oct 17 15:59:22 EDT 2010
`all_ascii(L)` is a function that accepts a list of strings L, and
returns True if all of those strings contain only ASCII chars, False
otherwise.
What's the fastest way to implement `all_ascii(L)`?
My ideas so far are:
1. Match against a regexp with a character range: `[ -~]`
2. Use s.decode('ascii')
3. `return all(31< ord(c) < 127 for s in L for c in s)`
Any other ideas? Which one do you think will be fastest?
Will reply with final benchmarks and implementations if there's any interest.
Thanks, D
More information about the Python-list
mailing list