Newbie: Check first two non-whitespace characters

Denis McMahon denismfmcmahon at gmail.com
Thu Dec 31 15:35:11 EST 2015


On Thu, 31 Dec 2015 10:18:52 -0800, otaksoftspamtrap wrote:

> Best to use re and how? Something else?

Split the string on the space character and check the first two non blank 
elements of the resulting list?

Maybe something similar to the following:

if [x for x in s.split(' ') if x != ''][0:3] == ['(', '(', '(']:
    # string starts '((('

-- 
Denis McMahon, denismfmcmahon at gmail.com



More information about the Python-list mailing list