I need to find out whether a name starts with any of a list\'s prefixes and then remove it, like:
if name[:2] in [\"i_\", \"c_\", \"m_\", \"l_\", \"d_\", \"t
Could use a simple regex.
import re prefixes = ("i_", "c_", "longer_") re.sub(r'^(%s)' % '|'.join(prefixes), '', name)
Or if anything preceding an underscore is a valid prefix:
name.split('_', 1)[-1]
This removes any number of characters before the first underscore.