Q:

How to split line into 0,1, or 2 arrays based on line content

I am writing a program that will receive input lines in one of four structures:
a,b
(a,b,c),d
a,(b,c,d)
(a,b),(c,d)

the number of members inside each parenthesis might change. Now, I want to translate each of the above lines as following
['a','b']
[['a','b','c'],'d']
['a',['b','c','d']]
[['a','b'],['c','d']]

I can think of a way to do this by checking each character, but knowing python, I'm certain there is a way to do this easily, probably using regular expressions. Is there?
Edit: Edited the desired output. 

A:

Consider:
import re, ast

input = """
a,b
(a,b,c),d
a,(b,c,d)
(a,b),(c,d)
"""

input = re.sub(r'(\w+)', r"'\1'", input)
for line in input.strip().splitlines():
    print ast.literal_eval(line)

> ('a', 'b')
> (('a', 'b', 'c'), 'd')
> ('a', ('b', 'c', 'd'))
> (('a', 'b'), ('c', 'd'))

This creates tuples, not lists, but that would be an easy fix.

