case insensitive lstrip function?

Marc 'BlackJack' Rintsch bj_666 at
Fri Mar 28 23:55:57 CET 2008

On Fri, 28 Mar 2008 15:48:09 -0700, Kelie wrote:

> Is there such a function included in the standard Python distribution?

AFAIK not.

> This is what I came up with. How to improve it? Thanks.
> def lstrip2(s, chars, ingoreCase = True):
>     if ingoreCase:
>         s2 = s.upper().lstrip(chars.upper())
>         return s[len(s)-len(s2):]
>     else:
>         return s.lstrip(chars)

What about this:

def lstrip2(string, chars, ignore_case=True):
    if ignore_case:
        chars = chars.lower() + chars.upper()
    return string.lstrip(chars)

	Marc 'BlackJack' Rintsch

More information about the Python-list mailing list