I have a list with elements that have unnecessary (non-alphanumeric) characters at the beginning or end of each string.
Ex.
\'cats--\'
I believe that this is the shortest non-regex solution:
text = "`23`12foo--=+" while len(text) > 0 and not text[0].isalnum(): text = text[1:] while len(text) > 0 and not text[-1].isalnum(): text = text[:-1] print text