> any() and all() also short-circuit, and they move the iteration out of > Python into the C runtime. My guess is the solutions with any() and > all() and equivalent hoisting of string.printable will be faster than > yours, but I don't want to take the time to check ATM...I would also try > using set(string.printable) instead of string.printable...
if they do, yeah, that'll be faster since it'll run in C. you're probably also right about set since it doesn't have to "look into a string" to see whether it has a character or not. (this is the same as the advantages that a hash table has over an array.). > Anyone feel like spending some time with timeit? Otherwise we're just > guessing anyway. i don't have any time myself either (getting ready for OSCON talk), but i'm not sure what terry's OP was about... looking for a well-written piece of code, a faster-performing snippet, or both? i think he was just unsatissfied with his 1st attempt. -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor