"1. 4x Apples. \n2. 5x Bananas \n3. 6x Oranges\n4. 3x Pears\n",
["4x Apples.", "5x Bananas", "6x Oranges", "3x Pears"]
a = "1. 4x Apples. \n2. 5x Bananas \n3. 6x Oranges\n4. 3x Pears\n"
b = "1. Ice cream \n2. Rice \n3. Flour\n4. Cola\n"
def to_list(string):
"""String to list"""
return string.replace('\n', '').replace('1.',).split()
y = to_list(a)
x = to_list(b)
import re
foo = '1. 4x Apples. \n2. 5x Bananas \n3. 6x Oranges\n4. 3x Pears\n'
bar = '1. Ice cream \n2. Rice \n3. Flour\n4. Cola\n'
def to_list(s):
return re.findall(r'\d+\.\s(.+?)(?=\s?\n)', s)
to_list(foo)
# ['4x Apples.', '5x Bananas', '6x Oranges', '3x Pears']
to_list(bar)
# ['Ice cream', 'Rice', 'Flour', 'Cola']
import re
a = "1. 4x Apples. \n2. 5x Bananas \n3. 6x Oranges\n4. 3x Pears\n"
b = "1. Ice cream \n2. Rice \n3. Flour\n4. Cola\n"
def to_list(data):
return [x.strip() for x in re.findall('\d+\.(.*)\n', data)]
y = to_list(a)
x = to_list(b)
print(y)
print(x)
def to_list(string):
"""String to list"""
return [phrase[2:].strip() for phrase in string.split("\n")][:-1]
y = to_list(a)
x = to_list(b)