Finding whether a string starts with one of a list's variable-length prefixes
问题 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_", "e_", "b_"]: name = name[2:] The above only works for list prefixes with a length of two. I need the same functionality for variable-length prefixes . How is it done efficiently (little code and good performance)? A for loop iterating over each prefix and then checking name.startswith(prefix) to finally slice the name according to the length of