How do I convert a list in Python 3.5 such as:
x=[1, 3, 5]
to an int of 135
(a whole int)?
Here is a more mathematical way that does not have to convert back and forth to string. Note that it will only work if 0 <= i <= 9.
>>> x = [1, 3, 5]
>>> sum(d * 10**i for i, d in enumerate(x[::-1]))
135
The idea is to multiply each element in the list by its corresponding power of 10 and then to sum the result.