I have a string that holds numbers. I want to check if the string has all the numbers between 0-9. Currently, the way I am checking is pretty slow and it will definitely be useless for large strings. Here is my code below:
import sys
# check if all numbers (0-9) exist in a string
num = "31586055033755830765"
for i in num:
if int(i) not in [0, 1, 2 ,3 ,4 ,5 ,6, 7, 8, 9]:
print("The string doesn't have all the numbers")
sys.exit(1)
The code works fine but is pretty slow. Is there a faster way to accomplish the task?