I have a list of statements. Each statement has a number of other statements separated by commas.
gf = ['citrus fruit,black bread,margarine,ready soups', 'tropical
fruit,yogurt,coffee, margarine', 'whole milk'] ## it has elements (lists with multiple items separated by EXTERNAL commas).
I need to transform it into:
gf_n = ['citrus fruit', 'black bread', 'margarine', 'ready soups', 'tropical fruit', 'yogurt', 'coffee', 'margarine','whole milk']
The individual elements (words or a group of words) can be repeated. In the future, I will need to calculate the frequency of every element (e.g. "citrus fruit") and the frequency of every two-item combination (e.g. 'black bread' and 'margarine')
Here is my code and the result is not what I need:
gf_list = list(gf.split(","))
gf_item = []
gf_item = [item for sublist in gf_list for item in sublist]
this is what I get surprisingly (letters - not words)
['c', 'i', 't', 'r', 'u', 's', ' ', 'f', 'r', 'u'] # first 10 elements
What do I do wrong?
SOLUTION (after some time I came up with this):
for subl in lst:
gf_item.append(subl.split(","))