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
i recently had a similar task of counting indents, because of which i wanted to count tab as four spaces:
def indent(string: str): return sum(4 if char is '\t' else 1 for char in string[:-len(string.lstrip())])