Description of problem
I need to get the first number from a given integer. This operation will be done millions of times, therefore I need to make sure that I use the most efficient way of doing this.
If the length of the integer affects the answer, then in my case I know that the integer will always be a 2 digit number.
What I tried
I have tried the methods mentioned below. Method 1 and 2 seems slow since I have to convert back and forth. Method 3 uses //, ** and % which I could assume are also heavy on the system. Is there a better way of performing this seemingly "simple" task?
# Method 1:
first_digit = int(str(x)[0])
# Method 2:
first_digit = int(str(x)[1:])
# Method 3:
first_digit = x // 10 % 10