str_dict = {}
strs=['sbc','scb','13','31','a']
for s in strs:
t = "".join(sorted(s))
if t in str_dict:
str_dict[t].append(s)
else:
str_dict[t] = [s]
print(str_dict.values())
python练习:字母异位词分组
最新推荐文章于 2024-04-25 00:28:21 发布