题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
stri = input() alpa = [i for i in stri if i.isalpha()] # 筛选字符 alpa = sorted(alpa,key=str.upper) # 将字符按照不区分大小进行排序 index = 0 for i in stri: if i.isalpha(): # 遍历源字符串,如果是字符就打印排序好的字符串 print(alpa[index],end='') index += 1 else: print(i, end='') # print(alpa) # print(alpa)