题解 | 字符串排序
字符串排序
https://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
old_str = list(input().strip())
def check(string: str):
return 97 <= ord(string.lower()) <= 122
new_str = [] # 保存字母
others = {} # 保存其它字符{index : value}
for idx, char in enumerate(old_str):
if check(char):
new_str.append(char)
else:
others.update({idx: char})
# 排序字母
new_str = sorted(new_str, key=str.lower)
for k, v in others.items():
new_str.insert(k, v)
print("".join(new_str))
