On 23 November 2011 17:10, Massi <massi_...@msn.com> wrote: > Hi everyone, > > I have to parse a string and splitting it by spaces. The problem is > that the string can include substrings comprises by quotations which > must mantain the spaces. What I need is to pass from a string like: > > This is an 'example string' > > to the following vector:
You mean "list" > ["This", "is", "an", "example string"] > Here's a way: >>> s = "This is an 'example string' with 'quotes again'" >>> [x for i, p in enumerate(s.split("'")) for x in ([p] if i%2 else p.split())] ['This', 'is', 'an', 'example string', 'with', 'quotes again'] -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list