Basically, I want to create a list of numeric values from a list of strings. I wrote a simple while loop to check each character in each string in the list, but it's not returning as expected. Is there a better way of doing this or am I messing something up? Here is my code:
textList = ["3", "2 string", "3FOO"]
newList = []
i= 0
foo = 0
while i < len(textList):
tmplist=[]
while foo < len(textList[i]):
bar = textList[i]
if bar[foo].isnumeric():
tmplist.append(str(bar[foo]))
foo += 1
tmpstring = str(''.join(tmplist))
newList.append(tmpstring)
i += 1
print(newList)
The expected output is
["3", "2", "3"]
However, I get:
["3", "", ""]
Can anyone explain why?