Convert List of String into Sorted List of Integer - Python Last Updated : 21 Feb, 2025 Comments Improve Suggest changes Like Article Like Report We are given a list of string a = ['3', '1', '4', '1', '5'] we need to convert all the given string data inside the list into int and sort them into ascending order so the output list becomes a = [1, 1, 3, 4, 5]. This can be achieved by first converting each string to an integer and then sorting the resulting list in ascending order. Various methods such as using map(), list comprehensions, loops and libraries like NumPy can be employed to perform this task.Using map() and sorted()We can convert a list of strings into a sorted list of integers using the map() and sorted() functions. map() function is used to apply int() to each string in the list and sorted() arranges the resulting integers in ascending order. Python a = ['3', '1', '4', '1', '5'] #all strings are converted into integers and sorted in ascending order a = sorted(map(int, a)) print(a) Output[1, 1, 3, 4, 5] Explanation:map(int, li) converts each string in the list to an integer.sorted() sorts the resulting integers.Using List Comprehension and sorted()We can use a list comprehension and sorted() to convert a list of strings into a sorted list of integers. List comprehension converts each string to an integer using int() and sorted() arranges the integers in ascending order. Python a = ['3', '1', '4', '1', '5'] # Convert each string number to an integer and sort the list in ascending order a = sorted([int(x) for x in a]) print(a) Output[1, 1, 3, 4, 5] Explanation:A list comprehension converts the strings to integers.sorted() then sorts the list of integersUsing int() in a for loopWe can use a for loop with int() to convert a list of strings into a sorted list of integers. First, iterate through list to convert each string to an integer, store the results in a new list and then use sorted() to sort the integers. Python a = ['3', '1', '4', '1', '5'] b = [] # Iterate through each string in the list 'a' for num in a: b.append(int(num)) # Convert each string to an integer and append to 'b' # Sort the list 'b' in ascending order b.sort() print(b) Output[1, 1, 3, 4, 5] Explanation:for loop iterates through each string in the list li, converts it to an integer using int(num) and appends the result to the list a.sort() method is then used to arrange the integers in the list a in ascending order, producing sorted list of integers.Using numpyWe can use NumPy to convert a list of strings into a sorted list of integers by first using numpy.array() to create a NumPy array of integers. Then, numpy.sort() function is applied to sort the array in ascending order. Python import numpy as np # List of strings representing integers a = ["10", "2", "30", "4", "25"] # Convert to NumPy array, sort, and convert back to list b = np.sort(np.array(a, dtype=int)).tolist() print(b) Output[2, 4, 10, 25, 30] Explanation:List li of strings is converted to a NumPy array of integers using np.array() with dtype=int and then sorted using np.sort().Sorted NumPy array is converted back to a Python list using .tolist() and printed. Comment More infoAdvertise with us Next Article Convert List of String into Sorted List of Integer - Python everythingispossible Follow Improve Article Tags : Python Python Programs python-list Python list-programs Practice Tags : pythonpython-list Similar Reads Python | Convert list of numerical string to list of Integers Many times, the data we handle might not be in the desired form for any application and has to go through the stage of preprocessing. One such kind of form can be a number in the form of a string that too is a list in the list and we need to segregate it into digit-separated integers. Let's discuss 5 min read Python | Convert List of String List to String List Sometimes while working in Python, we can have problems of the interconversion of data. This article talks about the conversion of list of List Strings to joined string list. Let's discuss certain ways in which this task can be performed. Method #1 : Using map() + generator expression + join() + isd 6 min read Python | Convert list into list of lists Given a list of strings, write a Python program to convert each element of the given list into a sublist. Thus, converting the whole list into a list of lists. Examples: Input : ['alice', 'bob', 'cara'] Output : [['alice'], ['bob'], ['cara']] Input : [101, 202, 303, 404, 505] Output : [[101], [202], 5 min read Python - Convert a String Representation of a List into a List Sometimes we may have a string that looks like a list but is just text. We might want to convert that string into a real list in Python. The easiest way to convert a string that looks like a list into a list is by using the json module. This function will evaluate the string written as JSON list as 2 min read Convert List to Delimiter Separated String - Python The task of converting a list to a delimiter-separated string in Python involves iterating through the list and joining its elements using a specified delimiter. For example, given a list a = [7, "Gfg", 8, "is", "best", 9] and a delimiter "*", the goal is to produce a single string where each elemen 3 min read Python - Convert Number to List of Integers We need to split a number into its individual digits and represent them as a list of integers. For instance, the number 12345 can be converted to the list [1, 2, 3, 4, 5]. Let's discuss several methods to achieve this conversion.Using map() and str() Combination of str() and map() is a straightforwa 3 min read Python | Convert given list into nested list Sometimes, we come across data that is in string format in a list and it is required to convert it into a list of the list. This kind of problem of converting a list of strings to a nested list is quite common in web development. Let's discuss certain ways in which this can be performed. Convert the 4 min read Python Program to Convert a list of multiple integers into a single integer There are times when we need to combine multiple integers from a list into a single integer in Python. This operation is useful where concatenating numeric values is required. In this article, we will explore efficient ways to achieve this in Python.Using join()join() method is the most efficient an 2 min read Convert Each Item in the List to String using Python Converting each item in a list to a string is a common task when working with data in Python. Whether we're dealing with numbers, booleans or other data types, turning everything into a string can help us format or display data properly. We can do this using various methods like loops, the map() fun 3 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 Like