题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
while True: try: strings = input() chars = '' for i in strings: if i.isalpha(): chars += i #key=lambda x: x.upper()或者x.lower()可以满足排序要求 chars_sorted = ''.join(sorted(chars, key=lambda x: x.upper())) # print(chars) # print(chars_sorted) index = 0 result = '' for j in range(len(strings)): if strings[j].isalpha(): #注意此处要用index不能用j result += chars_sorted[index] index += 1 else: result += strings[j] print(result) except: break