By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,630 Members | 1,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,630 IT Pros & Developers. It's quick & easy.

case insensitive lstrip function?

P: n/a
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)
Mar 28 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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)

Ciao,
Marc 'BlackJack' Rintsch
Mar 28 '08 #2

P: n/a
On Mar 28, 12:55 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
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.
Mar 29 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.