politweet / functions /functions.py
Demea9000's picture
changed topic so that topics are divided into columns
5214b07
raw
history blame
842 Bytes
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