File size: 1,177 Bytes
5214b07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297c37f
 
 
38b2250
 
 
 
 
 
297c37f
38b2250
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from re import sub


def separate_string(string):
    """
    This function returns a list of strings from a string.
    Example: separate_string('1. swedish 2. nuclear 3. hello world 4. uha yhd ikv hahd vva 5. ')
    returns ['swedish', 'nuclear', 'hello world', 'uha yhd ikv hahd vva', '']
    :param string: string to be separated
    :return: list of string items
    """
    list_string = string.split('.')
    list_useable = []
    for list_part in list_string:
        list_useable.append(list_part.split(' ', 1))

    final_list = []
    for li in list_useable[1:]:
        final_list.append(li[1])
    # remove numeric characters and spaces
    filter_numeric_regex = '[^a-z]'
    final_final_list = []
    for li in final_list:
        final_final_list.append(sub(filter_numeric_regex, ' ', li).strip())
    return final_final_list


def convert_to_tuple(string):
    """
    This function converts a string to a tuple.
    :param string:
    :return: tuple of strings
    """
    string = string.strip()
    return tuple(string.strip('()').split(', '))



if __name__ == '__main__':
    s = ' (politics, government, negative, sweden)'
    print(convert_to_tuple(s))