I know I can count the leading spaces in a string with this:
>>> a = \" foo bar baz qua \\n\" >>> print \"Leading spaces\", len(a) - le
Using next and enumerate:
next
enumerate
next((i for i, c in enumerate(a) if c != ' '), len(a))
For any whitespace:
next((i for i, c in enumerate(a) if not c.isspace()), len(a))