File size: 552 Bytes
4d5a6e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import re


def check_if_is_number(text: str):
    try:
        int(text)
        return True
    except ValueError:
        return False

def get_all_numbers_in_a_sentence(text: str):
    return [int(i) for i in re.findall(r'[-+]?\d+', text)]

def get_all_numbers_in_a_sentence_with_comma(text: str):
    #remove comma in numbers
    text = text.replace(',', '')
    return [int(i) for i in re.findall(r'[-+]?\d+', text)]

def get_all_numbers(text: str):
    return get_all_numbers_in_a_sentence(text) + get_all_numbers_in_a_sentence_with_comma(text)