How to Convert List to Int in Python
In this article, we will see how to convert list to int in Python.
We will discuss converting a list of integers into a single integer. Given a list of integers, below is a Python program to convert the given list into a single integer.
li = [1, 2, 4, 6, 7] #converting the integer list to string list s = [str(i) for i in li] #join list items using join() res = int("".join(s)) print(res)
Output:
12467
This can be done using map()
also. Let’s see that.
li = [1, 2, 4, 6, 7] res = int("".join(map(str, li))) print(res)
Output:
12467
Subscribe
Login
Please login to comment
0 Discussion