On 8 Mai, 20:46, Steven D'Aprano <st...@remove-this-
cybersource.com.au> wrote:

> def get_leading_whitespace(s):
>     t = s.lstrip()
>     return s[:len(s)-len(t)]
>
> >>> c = get_leading_whitespace(a)
> >>> assert c == leading_whitespace
>
> Unless your strings are very large, this is likely to be faster than any
> other pure-Python solution you can come up with.

Returning s[:-1 - len(t)] is faster.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to