The lstrip() function doesn't behave in exactly the way you think it might. x.lstrip(argument) removes any of the characters in argument from the left of the string x until it reaches a character not in argument.
So 'KEY_K'.lstrip('KEY_') generates '' because the last character, K, is in KEY_.
The lstrip() function doesn't behave in exactly the way you think it might. x.lstrip(argument) removes any of the characters in argument from the left of the string x until it reaches a character not in argument.
So 'KEY_K'.lstrip('KEY_') generates '' because the last character, K, is in KEY_.
It's right in the docs:
lstrip(...) S.lstrip([chars]) -> string or unicode
Return a copy of the string S with leading whitespace removed. If chars is given and not None, remove characters in chars instead. If chars is unicode, S will be converted to unicode before stripping
'K' is in 'KEY_', that's why your last example returns ''.
Note that 'K' would not have been removed if preceded by a character that is not in 'KEY_':
>>> 'KEY_xK'.lstrip('KEY_')
'xK'