# 去重且将排序,倒序 tmp = list(set(tmp)) tmp.sort(key=lambda x: len(x),reverse=True) # 搜出子串 sub_str = [] for i in range(len(tmp)-1): for j in range(i+1,len(tmp)): if tmp[j] in tmp[i]: sub_str.append(tmp[j]) # 得到最终的最长字符串 final_tmp = [] for i in tmp: # 得到不在子串中且不是单个字符的数据 if i notin sub_str and len(i)>=2: final_tmp.append(i)