
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Convert a list of multiple integers into a single integer in Python
Sometimes we may have a list whose elements are integers. There may be a need to combine all these elements and create a single integer out of it. In this article we will explore the ways to do that.
With join
The join method can Join all items in a tuple into a string. So we will use it to join each element of the list by iterating through them through a for loop.
Example
listA = [22,11,34] # Given list print("Given list A: ", listA) # Use res = int("".join([str(i) for i in listA])) # Result print("The integer is : ",res)
Output
Running the above code gives us the following result −
Given list A: [22, 11, 34] The integer is : 221134
With map and join
We can apply the map function to convert each element of the list into a string and then join each of them to form a final list. Applying the int function makes the final result an integer.
Example
listA = [22,11,34] # Given list print("Given list A: ", listA) # Use res = int("".join(map(str, listA))) # Result print("The integer is : ",res)
Output
Running the above code gives us the following result −
Given list A: [22, 11, 34] The integer is : 221134
- Related Articles
- Convert list of string into sorted list of integer in Python
- How to convert a list of lists into a single list in R?
- Convert a string representation of list into list in Python
- Convert set into a list in Python
- Convert a nested list into a flat list in Python
- How to convert list elements into a single string in R?
- Convert a list into tuple of lists in Python
- Convert number to list of integers in Python
- Convert list of numerical string to list of Integers in Python
- Convert list of tuples into list in Python
- Convert list into list of lists in Python
- How to convert a single character to its integer value in Python?
- How to convert an integer into a date object in Python?
- How to convert a list into a tuple in Python?
- Python program to convert a list of tuples into Dictionary

Advertisements