I am wondering if there is a nice way to convert a list of digits to an integer in python. That is, if I have mylist = [1, 5, 9]
I would like to do something like int(mylist)
to get an output of 159
. I am assuming that the input list simply has digits, and I want to use this to create a number. Currently the best I have is:
mylist = [1, 5, 9]
num = 0
for i in range(len(mylist)):
num += mylist[i] * 10 ** (len(mylist) - i - 1)
Which should work alright, but feels too explicit. Is there a neater/nicer way to do this?