case insensitive lstrip function?

K

Kelie

Hello,

Is there such a function included in the standard Python distribution?
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)
 
M

Marc 'BlackJack' Rintsch

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)

Ciao,
Marc 'BlackJack' Rintsch
 
K

Kelie

What about this:

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

Ciao,
Marc 'BlackJack' Rintsch

Thanks Marc. I think yours looks much better.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top