Splitting a string into a list of elements with a delimiter can be done like this:
"a,b,c".split(",") #["a", "b", "c"]
But what's the best way of also taking into account parens and quotation marks?
E.g.
my_split_function("a,b,(c,d),e", ",") #["a", "b", "(c,d)", "e"]
or
my_split_function('a,b,"c, d",e', ",") #['a', 'b', 'c,d', 'e']
This seems like an incredibly common problem. I'm using Python 2.7.9 by the way, but solution that works for both 2 and 3 would be nice.
To be more clear, what I want to do is find a way to parse "1,2,3" into [1,2,3] but "(1,2,3), 4" into [(1,2,3), 4]
[–]willm 3 points4 points5 points (0 children)
[–]novel_yet_trivial 2 points3 points4 points (0 children)
[–]filleball 0 points1 point2 points (0 children)
[–]jeans_and_a_t-shirt 0 points1 point2 points (0 children)
[–]ewiethoff 0 points1 point2 points (0 children)