"Bryan Fodness" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
I have a string (column names) that I need to split.

D_H = 'D 5 10 15 20 25 30 35 40 D Upper D Lower'

I cannot do a simple list(D_H).split because the last two strings have a space between them (D Upper and D Lower are two, not four labels).

Any suggestions?

How was the string built? Is it possible to delimit the columns with something besides a space, since a space is a valid character in a column name. Baring that, adding a little knowledge of the string is needed:

import re
D_H = 'D 5 10 15 20 25 30 35 40 D Upper D Lower'
print re.split(r'\s(?![UL])',D_H) # split on spaces not followed by U or L.
['D', '5', '10', '15', '20', '25', '30', '35', '40', 'D Upper', 'D Lower']

--
Mark


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to