On Tue, 28 Jul 2015 at 15:01 Victor Hooi <victorh...@gmail.com> wrote:
> I have a line that looks like this: > > 14 *0 330 *0 760 411|0 0 770g 1544g 117g > 1414 computedshopcartdb:103.5% 0 30|0 0|1 19m 97m > 1538 ComputedCartRS PRI 09:40:26 > > I'd like to split this line on multiple separators - in this case, > consecutive whitespace, as well as the pipe symbol (|). > Is this what you want: In [5]: def split(s): ...: elements = [] ...: for x in s.split(): # Split whitespace ...: elements.extend(x.split('|')) ...: return elements ...: In [6]: s = "14 *0 330 *0 760 411|0 0 770g 1544g 117g 1414 computedshopcartdb:103.5% 0 30|0 0|1 19m 97m 1538 ComputedCartRS PRI 09:40:26" In [7]: split(s) Out[7]: ['14', '*0', '330', '*0', '760', '411', '0', '0', '770g', '1544g', '117g', '1414', 'computedshopcartdb:103.5%', '0', '30', '0', '0', '1', '19m', '97m', '1538', 'ComputedCartRS', 'PRI', '09:40:26'] -- Oscar
-- https://mail.python.org/mailman/listinfo/python-list