I think you need to process each item in the list as a split string on whitespace.

a = ['1 2 3', '4 5 6', 'invalid']
numbers = []
for item in a:
    for subitem in item.split():
        if(subitem.isdigit()):
            numbers.append(subitem)
print(numbers)

['1', '2', '3', '4', '5', '6']

Or in a neat and tidy comprehension:

[item for subitem in a for item in subitem.split() if item.isdigit()]
Answer from paleolimbot on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-extract-numbers-from-list-of-strings
Python - Extract numbers from list of strings - GeeksforGeeks
July 11, 2025 - map(int, ...) function converts each found number from string to integer and the extend() method adds them to the list n. The result is a list of all extracted integers from the strings.
Discussions

How to extracts number from this python list
This has two loops; one to examine each character and extract only the digits, and a second one to iterate over my_list: >>> my_list = [ ' 14,200 new items ' , '15,200 new items '] >>> [char for char in my_list[0] if char.isdigit()] ['1', '4', '2', '0', '0'] >>> "".join([char for char in my_list[0] if char.isdigit()]) '14200' >>> int("".join([char for char in my_list[0] if char.isdigit()])) 14200 >>> def extract_int(istr): return int("".join([char for char in istr if char.isdigit()])) ... >>> extract_int(my_list[0]) 14200 >>> [extract_int(phrase) for phrase in my_list] [14200, 15200] >>> More on reddit.com
🌐 r/learnpython
29
18
June 25, 2022
How to extract numbers from a string in Python? - Stack Overflow
I would like to extract all the numbers contained in a string. Which is better suited for the purpose, regular expressions or the isdigit() method? Example: line = "hello 12 hi 89" Resul... More on stackoverflow.com
🌐 stackoverflow.com
extracting numbers from list of strings with python - Stack Overflow
I have a list of strings that I am trying to parse for data that is meaningful to me. I need an ID number that is contained within the string. Sometimes it might be two or even three of them. Example More on stackoverflow.com
🌐 stackoverflow.com
Extract numbers from a string list - python - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... If I have a list like this [ [100], [500], [300] ], what's the best way in python to extract the numbers from it? More on stackoverflow.com
🌐 stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › python-extract-numbers-from-list-of-strings
Python – Extract numbers from list of strings | GeeksforGeeks
January 30, 2025 - Python is renowned for its simplicity and versatility, making it a popular choice for various programming tasks. When working with lists, one common requirement is to extract substrings from the elements of the list and organize them into a new list. In this article, we will see how we can extract s ... We are given a string and we have to determine how many numeric characters (digits) are present in the given string.
🌐
TutorialsPoint
tutorialspoint.com › extract-numbers-from-list-of-strings-in-python
Extract numbers from list of strings in Python
May 5, 2020 - import re mixed_strings = ['abc123def', ... : [123, 456789, 42] Use split() for simple separator-based extraction, isnumeric() for mixed character strings, and regular expressions for complex pattern matching....
🌐
Delft Stack
delftstack.com › home › howto › python › python extract number from string
How to Extract Numbers From a String in Python | Delft Stack
March 11, 2025 - The function extract_numbers takes an input string and uses re.findall() to search for all occurrences of one or more digits (\d+). The result is a list of strings containing the numbers found in the input string.
🌐
GeeksforGeeks
origin.geeksforgeeks.org › python-extract-numbers-from-list-of-strings
Python | Extract numbers from list of strings - GeeksforGeeks
May 5, 2023 - Auxiliary Space: O(n). This method ... that contain multiple instances of digits. ... Use the map() and filter() functions in Python to extract the numbers from the strings....
Find elsewhere
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python extract numbers from string
Python Extract Numbers From String - Spark By {Examples}
May 21, 2024 - For each word, you can use the isnumeric() method to check if it consists entirely of numeric characters. If a word is numeric, you convert a string to an integer using int() and append it to the result list.
🌐
thisPointer
thispointer.com › home › python › extract numbers from string in python
Extract Numbers from String in Python - thisPointer
May 17, 2022 - The most easiest method is get_nums(), which is a function of nums_from_string library. Its only drwaback is that, it doesn’t comes bundled with python and you have to install it.
🌐
Finxter
blog.finxter.com › home › learn python blog › how to extract numbers from a string in python?
How To Extract Numbers From A String In Python? - Be on the Right Side of Change
February 25, 2023 - Thus to solve our problem, we must import the regex module, which is already included in Python’s standard library, and then with the help of the findall() function we can extract the numbers from the given string.
🌐
GeeksforGeeks
geeksforgeeks.org › python-extract-numbers-from-string
Python | Extract Numbers from String - GeeksforGeeks
September 16, 2024 - Let's discuss certain ways in which this problem can be solved in Python. ... Use a loop to iterate over each character in the string and check if it is a digit using the isdigit() method. If it is a digit, append it to a list.
🌐
Medium
beckmoulton.medium.com › practical-skills-for-extracting-string-numbers-in-python-12a8bf5957d0
Practical skills for extracting string numbers in Python | by Beck Moulton | Medium
November 14, 2024 - import re #Define a string containing ... example,re.findall()Method: Use regular expressions\d+Match one or more consecutive numbers.re.findall()Return a list containing all the matching numbers in the string....
🌐
CodeScracker
codescracker.com › python › program › python-extract-numbers-from-string.htm
Python Program to Extract Numbers from a String
print(end="Enter the String: ") text = input() textLen = len(text) nums = [] chk = 0 for i in range(textLen): if text[i].isdigit(): nums.append(text[i]) chk = 1 if chk==1: print("\nHere is a list of Numbers in String: ") numsLen = len(nums) for i in range(numsLen): print(end=nums[i] + " ") else: ...
🌐
Bomberbot
bomberbot.com › python › extracting-numbers-from-lists-of-strings-in-python-advanced-techniques-and-best-practices
Extracting Numbers from Lists of Strings in Python: Advanced Techniques and Best Practices - Bomberbot
For instance, to extract numbers with decimal points, we could use r'\d+(?:\.\d+)?'. For negative numbers: r'-?\d+(?:\.\d+)?'. And for numbers in scientific notation: r'-?\d+(?:\.\d+)?(?:[eE][-+]?\d+)?'. However, it's worth noting that while regex is powerful, it can be slower for very large lists compared to simpler methods. Additionally, complex regex patterns can sometimes be challenging to read and maintain. For simpler cases, Python's built-in string methods offer an intuitive and often faster approach: