def separate(string,domain): result = [] str_t = string.replace(domain,"").strip('.').split(".") str_t.reverse() for i in range(len(str_t)): tmp = (str_t[:i+1]).copy() tmp.reverse() result.append( ".".join(tmp) ) ## 格式 ['a.com','b.a.com','c.b.a.com'] return result