我有以下清单:
strs = ["tea","tea","tan","ate","nat","bat"]
我想对该列表中的字符串进行排序:
strs = ["aet","aet","ant","aet","ant","abt"]
我怎样才能做到这一点?
谢谢
尝试如下:
>>> [''.join(sorted(s)) for s in strs]
['aet', 'aet', 'ant', 'aet', 'ant', 'abt']
# Or
>>> list(map(''.join, map(sorted, strs)))
['aet', 'aet', 'ant', 'aet', 'ant', 'abt']
out = []
for val in strs:
out.append("".join(sorted(list(val))))
print(out)