How to split a string into a list of integers in Python

Splitting a string into integers creates a new list of the integers in the string. For example, splitting “1 2 3” into integers results in [1, 2, 3].

Solution for How to split a string into a list of integers in Python : You can use str.split() and map() to split a string into integers Call str.split() to split str into a list of strings representing each number. Use map(func, list) with int as func and list as the list of strings to create a map object with each string converted to an integer. Use list(mapping) to convert mapping, the object created by map to a list.


how-to-split-a-string-into-a-list-of-integers-in-python