Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- > python --version
- Python 2.7.2
- > python -m timeit -c '
- my_string = "qwer123asd!@#$%^"
- predef = set("0x#$qi")
- if set(my_string).issubset(predef):
- print "only predefined symbols"
- '
- 100000 loops, best of 3: 3.87 usec per loop
- > python -m timeit -c '
- import re
- pat = re.compile("^[0x#$qi]*$")
- my_string = "qwer123asd!@#$%^"
- if pat.match(my_string):
- print("Only predefined symbols!")
- '
- 100000 loops, best of 3: 5.15 usec per loop
- >
Add Comment
Please, Sign In to add comment