'Removing numbers from the first part of an array

I've been trying to remove numbers from the first part of my array, but I can't seem to find the right order to do it. In my logic, I should separate the part of the array that I need to extract the numbers and then use append to make the array complete again.

In my code, I would receive an input similar to:

["1518969489sunflower_of_the_year", 15, 8.99, 55,85]

My output must be:

["sunflower of the year", 15, 8.99, 55,85]

I've tried to do something like this, but I can't seem to find the right order to separate the letters and the _. Any input is very much appreciated. Thanks.

def extract_number (array):

array.split ("_")

####After removing the _, I can't seem to find a solution to separate the number from the word.

array.pop (0) #### After separating the numbers, I would delete with .pop.

Any input is very much appreciated, thank you!



Solution 1:[1]

See if this works for you

ls = ["1518969489sunflower_of_the_year", 15, 8.99, 55,85]

count = 0
for i in ls:
    if isinstance(i, str):
        new_num = ''.join([j for j in i if not j.isdigit()]).replace("_", " ")
        ls.pop(count)
        ls.insert(count,new_num)
    count+=1
print(ls)

Output

['sunflower of the year', 15, 8.99, 55, 85]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PandasasPD