I have a a user-inputted polynomial and I only want to use it if it only has characters in the string 1234567890^-+x.
How can I check if it does or not
Yet another way to do it, now using string.translate():
>>> import string
>>> all_chars = string.maketrans('', '')
>>> has_only = lambda s, valid_chars: not s.translate(all_chars, valid_chars)
>>> has_only("abc", "1234567890^-+x.")
False
>>> has_only("x^2", "1234567890^-+x.")
True
It is not the most readable way. It should be one of the fastest if you need it.