How to flatten/split items in list that are separated by " and '


I have the following list

mylist = ["'alpha','beta'",'delta','phi']

The combination of double quotes and single quotes for the first element is preventing me from properly working with alpha and beta separately. When i use

mylist[1] 

i get

delta

instead of beta, which is what i want

How do I split the first element of this list into 2 items and reinsert them so that I have have 4 items in this list?

Before you tell me not to write a list in this way, know that it is an output of a single line that i have already split from

"'alpha, beta'"

EDIT: Many of you are asking for the code that forms this list.... and I honestly couldn't post it because part of the code requires logging into a web-site to access restricted data.

The following code solved my problem:

mylist = [re.sub('^\W+|\W+$', '', i) for b in map(lambda x:re.split(',', x), mylist) for i in b]

Answer

You can use map:

import re

def split_words(d):
  return [re.sub('^\W+|\W+$', '', i) for b in map(lambda x:re.split("(?<='),(?=')", x), d) for i in b]

mylist = [["'alpha','beta'",'delta','phi'], ["'alpha','beta'",'delta','phi, theta']]
final_results = list(map(split_words, mylist))

Output:

[['alpha', 'beta', 'delta', 'phi'], ['alpha', 'beta', 'delta', 'phi, theta']]