khaykode khaykode - 27 days ago
99 0

A python script that extracts numbers from a string of characters.
Python 3 was used in coding it.

Python

Numbers Filtering

__author__ = 'KhayKode'

def extract_numbers(text):
    arr = []
    i, j = 0, 1

    isNumber = text[i:j].isdigit()     # check if the first character in the string is a number

    while j <= len(text):
        if isNumber:
            j += 1
            if j <= len(text):
                isNumber = text[i:j].isdigit()
                continue
            arr.append(text[i:j-1])
        else:
            arr.append(text[i:j-1])
            if arr[-1] == "":
                arr.remove(arr[-1])
        i, j = j, j + 1
        isNumber = text[i:j].isdigit()
    return arr