A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/python-integers-string-to-integer-list/ below:

Python - Integers String to Integer List

Python - Integers String to Integer List

Last Updated : 15 Jul, 2025

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)

Explanation

Using List Comprehension

Using 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)

Explanation

Using split() and a for Loop

Using 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)

Explanation



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4