Python 3.x 检查列表中的项目

Python 3.x 检查列表中的项目,python-3.x,Python 3.x,检查列表中的项目 检查列表中的项目 检查列表中的项目 检查列表中的项目不确定这是否是您想要的,但如下所示: from itertools import permutations s = ['8','role','lore','pre','erp','elor','orle','rep'] res = [] anag = set() for x in s: if x in anag: continue res.append(x) for per in pe

检查列表中的项目 检查列表中的项目 检查列表中的项目
检查列表中的项目

不确定这是否是您想要的,但如下所示:

from itertools import permutations 
s = ['8','role','lore','pre','erp','elor','orle','rep']
res = []
anag = set()
for x in s:
    if x in anag:
        continue
    res.append(x)
    for per in permutations(x):
        anag.add(''.join(per))
res = sorted(res)
#['8', 'role', 'pre']