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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top