johnsyweb

http://stackoverflow.com/q/10311602/78845

Apr 25th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. > python --version
  2. Python 2.7.2
  3. > python -m timeit -c '
  4. my_string = "qwer123asd!@#$%^"
  5. predef = set("0x#$qi")
  6.  
  7. if set(my_string).issubset(predef):
  8.        print "only predefined symbols"
  9. '
  10. 100000 loops, best of 3: 3.87 usec per loop
  11. > python -m timeit -c '
  12. import re                    
  13. pat = re.compile("^[0x#$qi]*$")
  14. my_string = "qwer123asd!@#$%^"
  15. if pat.match(my_string):          
  16.        print("Only predefined symbols!")
  17. '
  18. 100000 loops, best of 3: 5.15 usec per loop
  19. >
Add Comment
Please, Sign In to add comment