我想检查列表中的项目是否有任何整数,并且 return 列表中每个项目的整数是这样的吗?预期输出:['2', '12'] 怎么办?

I want to check the items in the list for any integers, and return each item's integers in the list like this? expected output: ['2', '12'] how to do?

预期输出 = ['2', '12']

当前输出=['2','1','2']

#程序

def listToString(s):
    str1 = " "
    print(s)
    new_str = str1.join(s)
    l = []
    for i in new_str:
        if i.isdigit():
            l.append(i)
    return l


s = ['abc2', 'is the', 'way12', 'for']
print(listToString(s))

像这样。

import re

def listToString(str_list): 
    print(s) 
    all_numbers = [] 
    for str_ in str_list: 
        all_numbers = all_numbers + re.findall('[0-9]+', str_) 
    return all_numbers

s = ['abc2', 'is the', 'way12', 'for'] 

print(listToString(s))

输出:

['abc2', 'is the', 'way12', 'for']
['2', '12']