Python - Integers String to Integer List Last Updated : 10 Jan, 2025 Comments Improve Suggest changes Like Article Like Report In this article, we will check How we can Convert an Integer String to an Integer List Using split() and map()Using split() and map() will allow us to split a string into individual elements and then apply a function to each element. Python s = "1 2 3 4 5" # Convert the string to a list of integers using split and map int_list = list(map(int, s.split())) print(int_list) Output[1, 2, 3, 4, 5] ExplanationThe split() method splits the input string s into individual string elements based on spaces.The map(int, s.split()) applies the int function to each element, converting them to integers, and list() collects the results into a list, which is then printed as [1, 2, 3, 4, 5].Using List ComprehensionUsing list comprehension allows you to create a new list by applying an expression to each element of an iterable. This method is compact and often more readable than traditional loops, making it ideal for transforming or filtering elements of a list or string. Python # Input string of integers s = "1 2 3 4 5" # Convert the string to a list of integers using list comprehension int_list = [int(i) for i in s.split()] # Print the result print(int_list) Output[1, 2, 3, 4, 5] Explanations.split() method splits the input string s into individual string elements, and the list comprehension [int(i) for i in s.split()] converts each element to an integer.The resulting list of integers [1, 2, 3, 4, 5] is stored in int_list and printed.Using split() and a for LoopUsing split() and a for loop together allows you to split a string into individual elements and then iterate through each element to apply a specific operation, such as converting each element to an integer. Python s = "1 2 3 4 5" # Initialize an empty list int_list = [] # Split the string and iterate over the parts for num in s.split(): int_list.append(int(num)) # Print the result print(int_list) Output[1, 2, 3, 4, 5] ExplanationThe s.split() method splits the input string s into individual string elements, and the for loop iterates through each element.Inside the loop, int(num) converts each string element to an integer, which is then appended to the int_list, resulting in [1, 2, 3, 4, 5]. Comment More infoAdvertise with us Next Article Python - Integers String to Integer List manjeet_04 Follow Improve Article Tags : Python Python Programs Python string-programs Practice Tags : python Similar Reads Python - Binary list to integer A binary list represents binary digits (0s and 1s) as individual elements of a list. This article will explore various methods to convert a binary list into an integer.Using int() with String ConversionThis is the most efficient method. By joining the binary list into a string and using the built-in 3 min read Integer to Binary String in Python We have an Integer and we need to convert the integer to binary string and print as a result. In this article, we will see how we can convert the integer into binary string using some generally used methods.Example: Input : 77Output : 0b1001101Explanation: Here, we have integer 77 which we converted 4 min read Split a List having Single Integer - Python We are given a list containing a single integer, and our task is to split it into separate digits while keeping the list structure intact. For example, if the input is a = [12345], the output should be [1, 2, 3, 4, 5]. Let's discuss different methods to do this in Python.Using List Comprehension We 2 min read Python - Convert List of Integers to a List of Strings We are given a list of integers and our task is to convert each integer into its string representation. For example, if we have a list like [1, 2, 3] then the output should be ['1', '2', '3']. In Python, there are multiple ways to do this efficiently, some of them are: using functions like map(), re 3 min read Python - Convert Integer Matrix to String Matrix Given a matrix with integer values, convert each element to String. Input : test_list = [[4, 5, 7], [10, 8, 3], [19, 4, 6]] Output : [['4', '5', '7'], ['10', '8', '3'], ['19', '4', '6']] Explanation : All elements of Matrix converted to Strings. Input : test_list = [[4, 5, 7], [10, 8, 3]] Output : [ 6 min read Python | Convert numeric String to integers in mixed List Sometimes, while working with data, we can have a problem in which we receive mixed data and need to convert the integer elements in form of strings to integers. This kind of operation might be required in data preprocessing step. Let's discuss certain ways in which this task can be performed. Metho 11 min read Python | Append String to list Sometimes, while working with data, we can have a problem in which we need to add elements to a container. The list can contain any type of data type. Let's discuss certain ways in Python in which we can perform string append operations in the list of integers.Example: Append String at the end of a 5 min read Python | Convert string enclosed list to list Given a list enclosed within a string (or quotes), write a Python program to convert the given string to list type. Examples: Input : "[0, 2, 9, 4, 8]" Output : [0, 2, 9, 4, 8] Input : "['x', 'y', 'z']" Output : ['x', 'y', 'z'] Approach #1: Python eval() The eval() method parses the expression passe 5 min read Python program to convert a byte string to a list of integers We have to convert a byte string to a list of integers extracts the byte values (ASCII codes) from the byte string and stores them as integers in a list. For Example, we are having a byte string s=b"Hello" we need to write a program to convert this string to list of integers so the output should be 2 min read Python - List of float to string conversion When working with lists of floats in Python, we may often need to convert the elements of the list from float to string format. For example, if we have a list of floating-point numbers like [1.23, 4.56, 7.89], converting them to strings allows us to perform string-specific operations or output them 3 min read Like